iphone - Does NSNotificationCenter removeObserver: deregister a VC from receiving MemoryWarning Notifications? -
i stumbled issue in app: tested didreceivememorywarning calls uiviewcontroller including follow-up calls viewdidunload.
this used work fine in older versions of app, not working within iphone simulator: didreceivememorywarning not called more.
this caused calling [nsnotificationcenter defaultcenter] removeobserver:self] in viewwilldisappear (self being uiviewcontroller) unregister lifecycle notifications did add in viewdidappear.
that global removeobserver: call did not remove added notifications, apparently system's uiapplicationdidreceivememorywarningnotification notification caused uiviewcontroller's didreceivememorywarning being called.
is behaviour design? not find reference/document pointing out, calling removeobserver: within uiviewcontroller breaks standard memorywarning handling.
yes, design.
this behavior doesn't surprise me @ all. implementation of uiviewcontroller opaque there no way know sure registering instances uiapplicationdidreceivememorywarningnotification didreceivememorywarning action make sense.
as general rule, it's bad practice use [[nsnotificationcenter defaultcenter] removeobserver:self] anywhere in dealloc. because, you've discovered, there can unpredictable side effects in superclass implementations. it's more predictable , easier debug/maintain code if follow convention of unregistering specific notifications registered for.
Comments
Post a Comment