You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
BLE Central starts adapter scan, awaits for device to advertise accepted service
Device is found, central connects to device and enables notifications
Central receives data, then disconnects device (at this point device could already have left range or been turned off)
Upon device re-discovery, central connects again to device, and from this point onwards an increased memory usage is noted (increases by ~2mb every 10 seconds or so, with no hard limit - has reached at least 500mb).
Example code, edited slightly from the source:
func (o*Bluetooth) Start() error {
println("enabling")
// Enable BLE interface.must("enable BLE stack", adapter.Enable())
// Start scanning.println("scanning...")
// Added a loop so we can start the scan again once we've finished with the current devicefor {
ch:=make(chan bluetooth.ScanResult, 1)
// Start scanning.println("scanning...")
err=adapter.Scan(func(adapter*bluetooth.Adapter, result bluetooth.ScanResult) {
println("found device:", result.Address.String(), result.RSSI, result.LocalName())
// Using a health thermometer service as a test here, can be swapped out with anything elseifresult.AdvertisementPayload.HasServiceUUID(bluetooth.ServiceUUIDHealthThermometer) {
adapter.StopScan()
ch<-result
}
})
vardevice*bluetooth.Deviceselect {
caseresult:=<-ch:
device, err:=adapter.Connect(result.Address, bluetooth.ConnectionParams{})
iferr!=nil {
println(err.Error())
returnerr
}
println("connected to ", result.Address.String())
// Handle some logic here on the deviceprintln("Disconnected")
device.Disconnect()
}
}
}
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?
The text was updated successfully, but these errors were encountered:
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.
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 #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?
The text was updated successfully, but these errors were encountered: