IOBluetoothRFCOMMChannel and memory management
IOBluetoothRFCOMMChannel and memory management
- Subject: IOBluetoothRFCOMMChannel and memory management
- From: Hugh Cole-Baker <email@hidden>
- Date: Thu, 24 Sep 2009 11:21:53 +0100
I am writing an application that communicates using an RFCOMM channel
to a mobile phone. I use the
openRFCOMMChannelAsync:withChannelID:delegate: method of IOBluetooth
device to open the channel. The docs for this method state "The RFCOMM
channel object is already retained when this function returns success;
the channel must be released when the caller is done with it" so I
don't retain the object from my code while using it. After using it I
set the channel delegate to nil, close the channel and release the
IOBluetoothRFCOMMChannel object, but this causes the app to crash
later when a message is sent to the already-deallocated channel object:
2009-09-24 11:16:30.817 bluetooth[9845:a0f] *** -
[IOBluetoothRFCOMMChannel retain]: message sent to deallocated
instance 0x163f7e40
(gdb) bt
#0 0x90510d27 in ___forwarding___ ()
#1 0x90510bf2 in __forwarding_prep_0___ ()
#2 0x9256ddc9 in objc_getProperty ()
#3 0x930181c4 in -[NotificationInfo object] ()
#4 0x93018a38 in btNotificationRFCOMMChannelTerminated ()
#5 0x93a26d40 in IODispatchCalloutFromCFMessage ()
#6 0x904d8df2 in __CFMachPortPerform ()
#7 0x904d8b8e in __CFRunLoopDoSource1 ()
#8 0x904d49e9 in __CFRunLoopRun ()
#9 0x904d2d34 in CFRunLoopRunSpecific ()
#10 0x904d2b61 in CFRunLoopRunInMode ()
#11 0x960e2fec in RunCurrentEventLoopInMode ()
#12 0x960e2da3 in ReceiveNextEventCommon ()
#13 0x960e2c28 in BlockUntilNextEventMatchingListInMode ()
#14 0x95714c95 in _DPSNextEvent ()
#15 0x9571450a in -[NSApplication
nextEventMatchingMask:untilDate:inMode:dequeue:] ()
#16 0x956d669b in -[NSApplication run] ()
#17 0x956ce735 in NSApplicationMain ()
#18 0x000023b1 in ?? ()
More worryingly, if the user closes the baseband connection (e.g. by
using the Bluetooth menu item's "Disconnect" option) the
IOBluetoothRFCOMMChannel object will be deallocated without my app
knowing about it.
It looks like it is actually necessary to retain the object I get from
openRFCOMMChannelAsync:withChannelID:delegate: while it is being used,
somewhat contrary to what the documentation says. Can anyone clarify
if this is the right thing to do in this case?
Thanks,
Hugh
--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Bluetooth-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden