iphone - Crash with CALayer, memory problem -
my hotpaw2 solution incremental drawing problem. alas, discovered issue solution implemented it. reveals memory-induced crash when press botton @ bottom of iphone suspend app , restart it. (i can run app indefinitely long don't this). crash occurs @ indicated line below, occurs in foobar, subclass of uiview:
- (void)drawrect:(cgrect)rect { cgcontextref ctx = uigraphicsgetcurrentcontext(); // @@crash here: program received signal exc_bad_access [backinglayer renderincontext:ctx]; // render backing layer current context [self randomrectangle: ctx]; } in interface of foobar have declared backing layer instance variable:
@private nstimer* timer; calayer *backinglayer; in implementation of foobar, backinglayer occurs once more, in initwithframe, in following paragraph:
backinglayer = self.layer; // [backinglayer retain]; // set color space , background color cgcolorspaceref colorspace = cgcolorspacecreatedevicergb(); cgfloat components[4] = {0.0f, 0.0f, 0.0f, 1.0f}; cgcolorref bgcolor = cgcolorcreate(colorspace, components); backinglayer.backgroundcolor = bgcolor; cgcolorrelease(bgcolor); cgcolorspacerelease(colorspace); i should there nstimer timer defined in initwithframe fires off tick method below 12 times second:
- (void)tick { // tell view needs re-draw if (running) { // go! // nslog(@"framerate: %2.1f, framecount: %d", framerate, framecount); [self setneedsdisplay]; framecount++; } } i've run instruments on app. no memory leaks detected. when run allocations , (a) suspend app physical button, (b) touch app icon make run again, see huge cluster of allocations (~2 gb) --- , crash.
-- jim
see last comment, should have put here. fixed setting bool running false when app enters inactive state, resetting true when becomes active once again.
Comments
Post a Comment