objective c - 60 hz NSTimer and autoreleased memory -
objective c - 60 hz NSTimer and autoreleased memory -
i have nstimer
firing @ 60 fps. updates c++ model , draws via quartz 2d. works except memory accumulates though not allocating anything. instruments reports no leaks many cfrunlooptimers
(i guess repeating nstimer
?) seem accumulating. clicking window or pressing key purges of them seem point autorelease pool not beingness drained enough. have rely on events cycle autorelease pool(s) or there improve way clear out memory?
any help appreciated, thanks
-sam
timer creation (timer
ivar):
timer = [nstimer scheduledtimerwithtimeinterval:1.0f / 60 target:self selector:@selector(update:) userinfo:nil repeats:yes];
update:
method:
- (void)update:(nstimer *)timer { controller->update(); [self.view setneedsdisplay:yes]; }
update:
after messing around little more i've made couple of additional observations.
1.) [self.view setneedsdisplay:yes]
seems culprit in spawning these cfrunlooptimers
. replacing [self.view display]
gets rid of issue @ cost of performance.
2.) lowering frequency 20-30 fps , keeping `[self.view setneedsdisplay:yes]' causes issue go away.
this seem imply setneedsdisplay:
doesn't called lot (maybe more time's per sec can displayed?). frankly can't understand problem "overcalling" if tell view redisplayed @ end of eventloop.
i sure missing here , additional help appreciated.
usually right solution create nested nsautoreleasepool around object-creations-heavy code.
but in case, seems objects autoreleased when timer re-schedule — piece of code can't control. , can't inquire topmost autorelease pool drain without releasing it.
in case, solution drop nstimer frame-rate syncing, , utilize cadisplaylink
instead:
cadisplaylink *framelink = [cadisplaylink displaylinkwithtarget:self selector:@selector(update:)]; // notify application @ refresh rate of display (60 hz) framelink.frameinterval = 1; [framelink addtorunloop:[nsrunloop mainrunloop] formode:nsdefaultrunloopmode];
cadisplaylink made synchronize drawing refresh rate of screen — seems candidate want do. besides, nstimer not precise plenty sync display refresh rate when running @ 60 hz.
objective-c memory nstimer autorelease
Comments
Post a Comment