Featured post
iphone - memory leak using MBProgressHUD -
i using mbprogresshub, variations on code found here.
some things code:
- the code in app delegate
- a number of other classes call it
- i'm using asynchronous nsurlconnection
- i not declare it: @property (nonatomic, retain) mbprogresshud *hud;
- i not: @synthesize hud;
- (and of course not release in dealloc)
i use follows:
- (void)setsearchingmode:(bool)issearching { // when network action, toggle network indicator , activity indicator if (issearching) { [uiapplication sharedapplication].networkactivityindicatorvisible = yes; uiwindow *thewindow = [uiapplication sharedapplication].keywindow; hud = [[mbprogresshud alloc] initwithwindow:thewindow]; [thewindow addsubview:hud]; //hud.labeltext = @"connecting"; [hud show:yes]; } else { [uiapplication sharedapplication].networkactivityindicatorvisible = no; [hud hide:yes]; [hud removefromsuperview]; [hud release]; } } - (void)setsearchingtext:(nsstring *)whattosay { hud.labeltext = whattosay; }
i sure code causing memory management problem somewhere. in crash log, get:
exception type: exc_bad_access (sigbus)
exception codes: kern_protection_failure @ 0x0000000c0 libobjc.a.dylib 0x000027d8 objc_msgsend + 16
1 0x00003120 -[myappdelegate setsearchingmode:] (myappdelegate.m:363)
2 0x00003458 -[myappdelegate connectiondidfinishloading:] (myappdelegate.m:341)
3 foundation 0x00032896 -[nsurlconnection(nsurlconnectionreallyinternal) senddidfinishloading] + 62
4 foundation 0x00032818 _nsurlconnectiondidfinishloading + 72
in connectiondidfinishloading call:
[self setsearchingmode:no];
i tried making property accessors hud, not able around line "[mbprogresshud alloc] initwithwindow" - , don't want keep on alloc'ing ivar!
thanks, if can point me in better direction here..
if happen end sequence of:
[self setsearchingmode:yes]; [self setsearchingmode:no]; [self setsearchingmode:no];
that code crash described because of dangling reference hud
. when [hud release];
, add hud = nil;
after line.
it isn't memory leak; over-release. or, more likely, dangling reference.
(and of course not release in dealloc)
why not? if retain it, better release it!
- Get link
- X
- Other Apps
Comments
Post a Comment