Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. Memory Heap Error bei einfacher Schleife

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    Memory Heap Error bei einfacher Schleife

    This topic has been deleted. Only users with topic management privileges can see it.
    • Dilldappe-io
      Dilldappe-io last edited by

      Hallo,
      hat jemand eine Idee, warum die einfache Schleife einen Speicherfehler verursacht?

      // Falls Fenster offen - Lampe leuchten lassen
      on({id: "zigbee.0.00124b002226d274.opened"/Is open/, change: "ne"}, async function (obj) {
      var value = obj.state.val;
      var oldValue = obj.oldState.val;
      if ((obj.state ? obj.state.val : "") == true) {
      while ((obj.state ? obj.state.val : "") == true) {
      setState("zigbee.0.7cb03eaa00a8b21c.state"/Switch state/, true);
      setState("zigbee.0.7cb03eaa00a8b21c.color"/Color/, '#ff0000');
      setStateDelayed("zigbee.0.7cb03eaa00a8b21c.state"/Switch state/, false, 10000, false);
      }
      }

      Ich meine, ich zähle ja nicht mal, geschweige dann, daß das ein Chuck Norris Skript ist, welches bis unendlich zählen kann (2x)
      Es handelt sich um einen Fenstersensor der "true" oder "false" zurückgibt. Ohne die Schleife funktioniert das Ganze und in der
      Schleife schaue ich nur, ob das Fenster immer noch auf ist. Ich habe es auch mit dem setzen einer Variablen versucht, das gleiche Ergebnis

      Caught by controller[0]: <--- Last few GCs --->
      Caught by controller[0]: [17795:0x5786868] 2026918 ms: Mark-sweep (reduce) 212.5 (216.9) -> 212.4 (217.2) MB, 2366.1 / 0.0 ms (average mu = 0.204, current mu = 0.002) allocation failure scavenge mi
      Caught by controller[0]: [17795:0x5786868] 2029196 ms: Mark-sweep (reduce) 212.9 (215.7) -> 212.7 (216.4) MB, 2272.5 / 0.0 ms (average mu = 0.109, current mu = 0.002) allocation failure scavenge mi
      Caught by controller[0]: <--- JS stacktrace --->
      Caught by controller[1]: FATAL ERROR: MarkCompactCollector: young object promotion failed Allocation failed - JavaScript heap out of memory
      instance system.adapter.javascript.0 terminated due to SIGABRT
      instance system.adapter.javascript.0 terminated with code NaN ()
      Restart adapter system.adapter.javascript.0 because enabled

      Vielen Dank im Voraus

      RPi 4 mit Raspbian
      Node.js 14.15.5
      js-Controller 3.2.16

      paul53 1 Reply Last reply Reply Quote 0
      • paul53
        paul53 @Dilldappe-io last edited by paul53

        @dilldappe-io sagte:

        while ((obj.state ? obj.state.val : "") == true) {
        

        erzeugt eine Endlosschleife.

        Dilldappe-io 1 Reply Last reply Reply Quote 0
        • Dilldappe-io
          Dilldappe-io @paul53 last edited by

          @paul53 naja, solange wie das Fenster eben auf ist bzw. der Kontakt eben "true" ist. Wenn das Fenster geschlossen wird, dann endet natürlich die Schleife, wenn nicht vorher js abstürzen würde
          fm.JPG

          AlCalzone Asgothian 2 Replies Last reply Reply Quote 0
          • AlCalzone
            AlCalzone Developer @Dilldappe-io last edited by

            @dilldappe-io Deine Endlosschleife sorgt für den Absturz.

            1 Reply Last reply Reply Quote 0
            • Asgothian
              Asgothian Developer @Dilldappe-io last edited by

              @dilldappe-io sagte in Memory Heap Error bei einfacher Schleife:

              naja, solange wie das Fenster eben auf ist bzw. der Kontakt eben "true" ist. Wenn das Fenster geschlossen wird, dann endet natürlich die Schleife, wenn nicht vorher js abstürzen würde

              Nein, tut sie nicht.

              Was da im Hintergrund passiert ist:

              • der Trigger wird aktiviert - dabei wird eine (temporäre) variable erstellt die die entsprechenden Daten beinhaltet (alten wert, neuen wert, etc)
              • dann läuft die "while" schleife synchron los
              • da du immer auf "variable=true" vergleichst, und innerhalb der Schleife den Wert der Variable nicht veränderst ist das eine Endlosschleife.
              • wenn der Trigger nocheinmal aktiv wird wird eine neue (temporäre) variable erzeugt, nicht die bestehende Variable angepasst.

              Was soll das machen ? Ein Blinklicht ?

              Wenn ja, dann:
              Screen Shot 2021-02-14 at 19.10.25 .png

              Dilldappe-io 1 Reply Last reply Reply Quote 0
              • Dilldappe-io
                Dilldappe-io @Asgothian last edited by

                @asgothian thx

                D 1 Reply Last reply Reply Quote 0
                • D
                  dkr @Dilldappe-io last edited by

                  @dilldappe-io Bei mir hat das Script mit der Verzögerung nicht funktioniert. Aber ich habe an meinem Shelly RGBW2 dann die App-Einstellung gefunden, ihn immer blinken zu lassen.
                  Nun schallte ich ihn vom ioBroker nur mit der Farbe und ein/aus.

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post

                  Support us

                  ioBroker
                  Community Adapters
                  Donate

                  565
                  Online

                  31.8k
                  Users

                  80.0k
                  Topics

                  1.3m
                  Posts

                  5
                  7
                  257
                  Loading More Posts
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes
                  Reply
                  • Reply as topic
                  Log in to reply
                  Community
                  Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                  The ioBroker Community 2014-2023
                  logo