As @matt says that if you just do nothing, ARC should be cleared when your object is freed. The DBRequest
assignment that you create for the instance variable is handled by the fact that (assuming, of course, your object is superior to the object you create).
If you need to free DBRequest
before your object dies, you will need an ARC-compatible "trick" equivalent to [[theDbRequest retain] autorelease]
. Now, if you do not create your own auto-join pools, your previous approach will fire at the end of the current event. Following this logic, try:
- Add a method to your class that simply sets
theDbRequest
to nil
, name it cleanUpTheDbRequest
. - Change the delegate callback to call
[self performSelectorOnMainThread:@selector(cleanUpTheDbRequest) withObject:nil waitUntilDone:NO]
instead of directly assigning nil
to theDbRequest
This should delay assignment of nil
until the end of the current event, just as your “automaton” did. It also works if your DBRequest
lives in several events - the previous method fires at the end of the event that autorelease
is called autorelease
, this method calls the delegate method at the end of the event.
source share