Benches Uncategorized

1

Memory leak in Thread

apple Verified

Imported from the Apple Support Forums via the Wayback Machine 🔗

Hi,

I am new to xCode. I am writing an application and found some memory leak I do not know how to fix. I hope you can help my.

Here is my code


- (void) updateImage:(UIImage*)img
{
[NSThread detachNewThreadSelector:@selector(processUpdataImage:) toTarget:self withObject:img];
}
- (void)processUpdataImage:(id)image {
NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init];

...// long work with the image

[autoreleasepool release];

[NSThread exit];
}

I ran it with Performance Tool and it reported a 3.5k memory leak in this piece of code with the trace like:

4 JJJ -[MyViewController updateImage:] MyViewController.m:119

3 Foundation +[NSThread detachNewThreadSelector:toTarget:withObject:]

2 Foundation -[NSThread start]

1 libSystem.B.dylib pthread_create

0 libSystem.B.dylib malloc

Could anyone tell me what I did wrong and how to fix the memory leak?

Thank you very much.

ff

1 reply

Sign in or join Beachball Help to reply.

  1. 0

    xnav

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    The NSThread Class Ref says this about 'NSThread exit':

    Invoking this method should be avoided as it does not give your thread a chance to clean up any resources it allocated during its execution.