Open jasday opened 8 months ago
I think the example code is good, instead there could be a problem in gap_linux.go. I see the number of goroutines keep incrasing together with memory usage, even after trying to connect once.
I can't see anywhere (*device.Device1).UnwatchProperties
get called while there is (*device.Device1)WatchProperties
. This can make underlying dbus signal channel not get unregistered, then result in leaking a goroutine for every single deffered undelivered signal from dbus.
https://github.com/tinygo-org/bluetooth/blob/d0c7887b81e136df90b732d1162cdb335633aafa/gap_linux.go#L326-L331
I forked and added a defer d.device.UnwatchProperties(d.propchanged)
and it seems okay so far.
They are trying to remove the dependency on muka/bluetooth, so I doubt this will be fixed.
This seems to have been fixed in the latest v0.9.0 - When simply connecting to a device and disconnecting the memory no longer increases and will remain fairly stable. There is however increasing memory usage when connecting to a device and enabling notifications as mentioned in https://github.com/tinygo-org/bluetooth/issues/260.
Expanding on the example
heartbeat-monitor
, I'm getting what appears to be a memory leak when re-connecting to a device after the first connection.An example use case:
Example code, edited slightly from the source:
Go version: 1.22.1 tinygo/x/bluetooth: 0.8.0
Compiling onto Linux Arm64, with a IW416 SOC
Am I doing anything wrong based on the example code? The only real difference here is the added loop, which (hopefully) allows for scanning and connecting to different devices. (I need to be able to connect to multiple devices with various different services at unknown times, so this is just attempting to get the basics working, so I need the ability to restart the scan once the operation on the current device is finished)
Any ideas?