开发者

iphone app NSNumber memory leak

I'm having a memory leak and I have no clue where it comes from and how to fix it.

At some point i calculate the distance between 2 locations.

double calc = [self getDistance:location to:otherLocation];
NSNumber *distance = [NSNumber numberWithDouble开发者_运维问答:calc];

in instruments i get as leaked object NSCFNumber and it identifies

NSNumber *distance = [NSNumber numberWithDouble:calc];

as the line causing this.

I'm at a loss. Please help.

thanks in advance, Michiel


There's nothing wrong with what you're doing there. The NSNumber has a +0 retain count (autoreleased), so you're probably retaining that NSNumber somewhere else and forgetting to release it.


Leaks shows you where an object that is leaking is CREATED.

If you think about it, there's really nothing else Leaks can show you - it's leaking because the object should have been released at some point, and Leaks can't show you code that does not exist!


I don't believe that you have problem on the NSNumber line.

I have run the following code and I've got no problems

code>double calc = 10.1234567;
    NSNumber *distance = [NSNumber numberWithDouble:calc];

    NSLog(@"calc: %f | %f", calc, [distance doubleValue]);

I believe that your problem is in your method "getDistance: to:"

Do like I have done. put a static value, instead of the method and check if it is ok.

Cheers,
VFN

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜