Memory Leak at characteristicvaluechanged

Posted on
  • Hello,

    I am trying to communicate with another device over Bluetooth.
    But everytime I receive a packet on the Puck.js it uses memory and don't release it.
    So after a few packets, the memory becomes less an I get an error Message --> MEMORY_BUSY.
    On the Screenshot you can see how the memory decreases. (it starts a 1800 free blocks)
    After I got the MEMORY_BUSY message it no longer receive every packet, so I miss most of the packets.

    I think there must be a Memory Leak in the "characteristicvaluechanged" function
    Do someone have simular problems and have found a solution for this problem ?

        function(d) {
          device = d;
          return device.getPrimaryService("180D");
          service = s;
          return service.getCharacteristic("2A37");
          read_char = rd;
          read_char.on('characteristicvaluechanged­', function(e) {
            event = e;
          return read_char.startNotifications();

    1 Attachment

    • BLE_Memory_Leak.png
  • Ouch - thanks for letting me know, I'll check into it.

    Is there any other code running on the device, or is it literally just what you have above? And are you running on 1v94, or one of the 'latest' builds for Puck.js?

    MEMORY_BUSY can occur when something happens in an IRQ that needs variables while the device is doing garbage collection in the main loop. Usually that's rare, but when memory runs low it can cause GC passes to fire more often, which could be making it happen far more frequently.

  • Thanks for the fast reply.

    I'm currently running on 1V94 with only the code I have posted above.

  • Ok, great! I'm away from the office at the moment but I'll try and test this when I get back

  • I haven't had a chance to test this on real hardware yet but I'm certain I found the problem and fixed it (I tested on build for my PC). It was a regression introduced when I started making the Bluetooth libraries return DataViews to be a bit more standards compliant.

    If you install the puck.js zip file from­master/ it should have the fix in.

  • Your fix seems to work

    Thanks for the fast solution! :)

  • No problem! It helps a huge amount to have a nice simple bit of code to test with.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Memory Leak at characteristicvaluechanged

Posted by Avatar for user83157 @user83157