dgtavr
dgtavr

Reputation: 11

Memory leaks in CoreMotion

Following is my code in vievDidLoad

CMMotionManager *motionmanager = [[[CMMotionManager alloc]init]autorelease];

NSString string1 = [NSString stringwithFormat:@"%s", ([motionmanager.isGyroAvailable} ? @"Available" : @"Not Available"));

In Instruments i get memory leaks referring CMMotionManagerInternal in XCode 4.5 What's wrong with my code?

Upvotes: 1

Views: 796

Answers (2)

ianolito
ianolito

Reputation: 3651

It seems to be a bug in the simulator. It's working properly on the device.

Upvotes: 1

Michał Zygar
Michał Zygar

Reputation: 4092

The CMMotionManagerline seems fine, however you should consider keeping the reference (make it instance variable and not autorelease it) and release the CMMotionManager manually when you stop updating data from it.

The other line bothers me more. You have

NSString string1 = [NSString stringwithFormat:@"%s", ([motionmanager.isGyroAvailable} ? @"Available" : @"Not Available"));

While you should have:

NSString *string1 = [NSString stringwithFormat:@"%@", ([motionmanager.isGyroAvailable} ? @"Available" : @"Not Available"));

so string1 should be a pointer and format is @"%@" not @"%s".

Upvotes: 1

Related Questions