I have searched StackOverflow for similar topics; there are two similar posts, but I am a bit of a dummy and do not understand the answers given. My issue is that when I run this code without specifying that it should go on a dispatch queue, the live bytes settle down and do not keep increasing, but when I specify that it should go on a dispatch queue the live bytes eventually go through the roof. The stuff that goes on between
//Do lots of stuff here
//Finish lots of stuff here
is pretty heavy so I would like it not on the main thread: I want the results to provide a continuous update to the rest of the algorithm. Also, I get occasional bizarre behavior in the graphical display when the dispatch lines are commented out. But using the dispatch queue the way I have written it causes the live bytes to blow up, while if I comment these lines out the live byte number settles down to a constant level.
What am I doing wrong? Thanks in advance!
I start the NSTimer in the main thread:
-(void) startGeoHardware
{
if (self.geoHardwareArrayTimer == nil)
{
self.geoHardwareArrayTimer = [NSTimer scheduledTimerWithTimeInterval:arrayTimerUpdate
target:self
selector:@selector(startGeoHardWareArray:)
userInfo:nil
repeats:YES];
}
}
and then call the method
- (void) startGeoHardWareArray: (NSTimer *)geoHardwareArrayTimer //: (CMCalibratedMagneticField)field
{
dispatch_queue_t runGeoHardwareArrayQueue = dispatch_queue_create("GeoHardwareArray",NULL);
dispatch_async(runGeoHardwareArrayQueue, ^{
//Do lots of stuff here
//Finish lots of stuff here
});
dispatch_release(runGeoHardwareArrayQueue);
}
The geoHardwareArrayTimer is defined in the .h file as
NSTimer *geoHardwareArrayTimer;
}
@property(nonatomic,retain) NSTimer *geoHardwareArrayTimer;
and is synthesized in the .m file. and is deallocated
if (self.geoHardwareArrayTimer != nil)
{
[self.geoHardwareArrayTimer invalidate];
self.geoHardwareArrayTimer = nil;
}
[super dealloc];