ios - Proper memory management when invoking a delegate callback that may cause object to be released -


i'm trying figure out best practice memory management around invoking delegate callback. 1 issue had seen in past invoking delegate callback may cause object deallocated before returning, may cause crash if object tries access own properties after invoking callback.

for example, object (e.g. a) may this:

- (void)dostuff {     [_delegate done];     nslog(@"msg = %@", _msg); } 

if invoking done leads a getting deallocated, subsequent attempt access _msg result in bad_access crash.

it possible around by, say, delaying invocation of done till next run loop (e.g. doing dispatch_async), force have make asynchronous. alternatively, can retain self prior calling done , releasing right after, seems hacky workaround well. 1 have recommended style dealing issue?

i'm not sure question has 'delegates' honest more memory management in general.

if you're not finished object make sure still 'retaining' it. when you're finished 'release' , don't access further.

also try , move arc if possible , life becomes easier! :)


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -