ios - NSRecursiveLock Deallocated -
i have ios app multiple view controllers , arc enabled. 1 of view controllers has iboutlet
uiscrollview
, uipagecontrol
. when view controller loaded error printed in console:
*** -[nsrecursivelock dealloc]: lock (<nsrecursivelock: 0xcb88cb0> '(null)') deallocated while still in use
while trying fix problem, created symbolic breakpoint symbol _nslockerror
module set foundation. xcode breaks breakpoint 1.1 on "0x12d2b58: pushl %ebp"
, on thread 1.
foundation`_nslockerror: ----------------------------------------------------- |> 0x12d2b58: pushl %ebp <|thread 1: breakpoint 1.1| ----------------------------------------------------- 0x12d2b59: movl %esp, %ebp 0x12d2b5b: subl $8, %esp 0x12d2b5e: calll 0x12d2b63 ; _nslockerror + 11 0x12d2b63: popl %eax 0x12d2b64: leal 2118709(%eax), %eax 0x12d2b6a: movl %eax, (%esp) 0x12d2b6d: calll 0x125689d ; nslog 0x12d2b72: addl $8, %esp 0x12d2b75: popl %ebp 0x12d2b76: ret
here code in application problematic viewcontroller:
header file (.h):
#import <uikit/uikit.h> @class aboutviewcontroller; @protocol aboutviewcontrollerdelegate - (void)aboutviewcontrollerdidfinish:(aboutviewcontroller *)controller; @end @interface aboutviewcontroller : uiviewcontroller<uiscrollviewdelegate> @property (strong, nonatomic,retain) id <aboutviewcontrollerdelegate> delegate; @property (nonatomic,strong,) iboutlet uiscrollview *scrollview; @property (nonatomic, strong) iboutlet uipagecontrol *pagecontrol; @property (nonatomic, strong) nsarray *imagearray; @property(nonatomic, assign) iboutlet uilabel *label; - (ibaction)done:(id)sender; //returns main menu after button pressed @end
implementation file (.m):
#import "aboutviewcontroller.h" @interface aboutviewcontroller () @end @implementation aboutviewcontroller @synthesize scrollview; @synthesize pagecontrol; @synthesize imagearray; int page; - (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil { self = [super initwithnibname:nibnameornil bundle:nibbundleornil]; if (self) { // custom initialization } return self; } - (void)viewdidload { [super viewdidload]; //load images scrollview in array imagearray = [[nsarray alloc] initwithobjects:@"1.png", @"2.png", @"3.png", nil]; (int = 0; < [imagearray count]; i++ ) { int page = scrollview.contentoffset.x / scrollview.frame.size.width; cgrect frame; frame.origin.x = self.scrollview.frame.size.width * i; frame.origin.y = 0; frame.size = self.scrollview.frame.size; uiimageview *imageview = [[uiimageview alloc] initwithframe:frame]; imageview.image = [uiimage imagenamed:[imagearray objectatindex:i]]; [self.scrollview addsubview:imageview]; nslog (@"page %d",page); if (page==0) { self.label.text = [nsstring stringwithformat:@"%s","page1"]; } } scrollview.contentsize = cgsizemake(scrollview.frame.size. width *[imagearray count], scrollview.frame.size.height); } #pragma mark - uiscrollview delegate - (void)scrollviewdidscroll:(uiscrollview *)sender { cgfloat pagewidth = self.scrollview.frame.size.width; //calculate current page in scrollview int page = floor((self.scrollview.contentoffset.x - pagewidth / 2) / pagewidth) + 1; self.pagecontrol.currentpage = page; nslog (@"page %d",page); if (page==0) { //change image caption self.label.text = [nsstring stringwithformat:@"%s","hello"]; [uiview beginanimations:nil context:null]; [uiview setanimationduration:1.0]; [_label setalpha:1]; [uiview commitanimations]; } if (page==1) { //change image caption self.label.text = [nsstring stringwithformat:@"%s","world"]; [uiview beginanimations:nil context:null]; [uiview setanimationduration:1.0]; [_label setalpha:1]; [uiview commitanimations]; } if (page==2) { //change image caption self.label.text = [nsstring stringwithformat:@"%s","foobar"]; [uiview beginanimations:nil context:null]; [uiview setanimationduration:1.0]; [_label setalpha:1]; [uiview commitanimations]; } } - (ibaction)done:(id)sender { [self.delegate aboutviewcontrollerdidfinish:self]; } @end
after (lldb)bt:
* thread #1: tid = 0x1c8f63, 0x012d2b58 foundation`_nslockerror, queue = 'com.apple.main-thread, stop reason = breakpoint 1.1 frame #0: 0x012d2b58 foundation`_nslockerror frame #1: 0x01247153 foundation`-[nsrecursivelock dealloc] + 159 frame #2: 0x01820692 libobjc.a.dylib`objc_object::sidetable_release(bool) + 268 frame #3: 0x01821adf libobjc.a.dylib`-[nsobject release] + 25 frame #4: 0x05a89385 uifoundation`_freeextradata + 48 frame #5: 0x05a895d5 uifoundation`-[nslayoutmanager dealloc] + 381 frame #6: 0x01820692 libobjc.a.dylib`objc_object::sidetable_release(bool) + 268 frame #7: 0x01821adf libobjc.a.dylib`-[nsobject release] + 25 frame #8: 0x00a91065 uikit`-[uitextview dealloc] + 168 frame #9: 0x00453e6b uikit`-[uiview release] + 89 frame #10: 0x0045f2d4 uikit`-[uiview(hierarchy) removefromsuperview] + 292 frame #11: 0x0047b4fd uikit`-[uiscrollview removefromsuperview] + 84 frame #12: 0x004565db uikit`-[uiview dealloc] + 432 frame #13: 0x00477eaf uikit`-[uiscrollview dealloc] + 1156 frame #14: 0x00453e6b uikit`-[uiview release] + 89 frame #15: 0x0045f2d4 uikit`-[uiview(hierarchy) removefromsuperview] + 292 frame #16: 0x0047b4fd uikit`-[uiscrollview removefromsuperview] + 84 frame #17: 0x004565db uikit`-[uiview dealloc] + 432 frame #18: 0x00453e6b uikit`-[uiview release] + 89 frame #19: 0x01ba2380 corefoundation`cfrelease + 272 frame #20: 0x01bc18b4 corefoundation`-[__nsarraym dealloc] + 196 frame #21: 0x01820692 libobjc.a.dylib`objc_object::sidetable_release(bool) + 268 frame #22: 0x0181fe81 libobjc.a.dylib`objc_release + 49 frame #23: 0x01820ce7 libobjc.a.dylib`(anonymous namespace)::autoreleasepoolpage::pop(void*) + 537 frame #24: 0x01bc1fc8 corefoundation`_cfautoreleasepoolpop + 24 frame #25: 0x00402c6e uikit`_wraprunloopwithautoreleasepoolhandler + 59 frame #26: 0x01be89ee corefoundation`__cfrunloop_is_calling_out_to_an_observer_callback_function__ + 30 frame #27: 0x01be893f corefoundation`__cfrunloopdoobservers + 399 frame #28: 0x01bc6cb0 corefoundation`__cfrunlooprun + 1936 frame #29: 0x01bc610d corefoundation`cfrunlooprunspecific + 445 frame #30: 0x01bc5f3b corefoundation`cfrunloopruninmode + 123 frame #31: 0x032e2ff2 graphicsservices`gseventrunmodal + 192 frame #32: 0x032e2e19 graphicsservices`gseventrun + 104 frame #33: 0x004054eb uikit`uiapplicationmain + 1225 frame #34: 0x0000789d monarch`main(argc=1, argv=0xbfffee1c) + 141 @ main.m:16
my question why nsrecursivelock
deallocated in first place?
i never mentioned nsrecursivelock
in code. there similar question on not detailed.
does arc come play here?
i don't know if related problem, think properties not correctly configured. recommended use "weak" , not "strong" or "assign" "iboutlet" properties (usually outlet subview of view controller's "view" property, these subviews retained "view" property).
also have delegate using strong , retain, don't need both, since you're using arc, use "strong" keyword only, , don't use "retain" anymore. , way, since delegate, should use "weak" property in order avoid circular reference.
Comments
Post a Comment