Re: Memory leaks in NSTask? (Instruments)
Re: Memory leaks in NSTask? (Instruments)
- Subject: Re: Memory leaks in NSTask? (Instruments)
- From: Joar Wingfors <email@hidden>
- Date: Tue, 25 Mar 2014 18:11:06 -0700
First of, this is not a tools question, so not really appropriate for this list.
That said, for this type of test you'd want to do something like this:
int main(int argc, const char * argv[])
{
@autoreleasepool {
NSString *speakingPhrase = @“This is spoken text.”;
for (;;) {
@autoreleasepool {
NSTask *speakTask = [[NSTask alloc] init];
speakTask.launchPath = @"/usr/bin/say";
speakTask.arguments = @[speakingPhrase];
[speakTask launch];
[speakTask waitUntilExit];
}
}
}
return 0;
}
Joar
On 25 mar 2014, at 17:49, Carl Hoefs <email@hidden> wrote:
> OSX 10.9.2, Xcode 5.1, ARC
>
> I use NSTask for a bunch of things in my ObjC app but discovered that it keeps memory allocated even after it's done and gone. So I isolated an NSTask launch in a little for() loop just to see if that was it, and also to show its effect more prominently in Instruments. This is built with ARC set to Yes.
>
> #import <Foundation/Foundation.h>
> int main(int argc, const char * argv[])
> {
> @autoreleasepool {
> NSString *speakingPhrase = @“This is spoken text.”;
> for (;;) {
> NSTask *speakTask = [[NSTask alloc] init];
> speakTask.launchPath = @"/usr/bin/say";
> speakTask.arguments = @[speakingPhrase];
> [speakTask launch];
> [speakTask waitUntilExit];
> }
> }
> return 0;
> }
>
> When I run Instruments, memory starts at 730K but grows very quickly to over 1MB and beyond, never stopping. I also tried the non-ARC way (-alloc/-release) with the same results, with an explicit [speakTask release], and an autorelease pool + release within the for() loop. Same results.
>
> Instruments shows memory being accumulated under “All Heap Allocations”. What in particular should I be looking at? Is NSTask just leaky? Surely I'm just doing something wrong here...
> -Carl
>
>
> # Address Category Timestamp Live Size Library Caller
> 0 0x100501360 Malloc 128 Bytes 00:00.648.373 • 128 Bytes Foundation +[NSIndexSet indexSet]
> 1 0x100606da0 Malloc 256 Bytes 00:00.648.566 • 256 Bytes Foundation -[NSConcreteTask dealloc]
> 2 0x100203870 Malloc 128 Bytes 00:00.648.811 • 128 Bytes Foundation -[NSFileManager stringWithFileSystemRepresentation:length:]
> 3 0x1002038f0 CFString (immutable) 00:00.648.815 • 128 Bytes Foundation -[NSPlaceholderString initWithBytes:length:encoding:]
> 4 0x100203970 __NSDictionaryM 00:00.648.828 • 48 Bytes Foundation +[NSTask currentTaskDictionary]
> 5 0x1002039a0 Malloc 64 Bytes 00:00.648.829 • 64 Bytes Foundation +[NSTask currentTaskDictionary]
> 6 0x1002039e0 Malloc 64 Bytes 00:00.648.829 • 64 Bytes Foundation +[NSTask currentTaskDictionary]
> 7 0x100203ae0 Malloc 256 Bytes 00:00.648.832 • 256 Bytes Foundation +[NSTask currentTaskDictionary]
> 8 0x100202ff0 __NSArrayI 00:00.648.843 • 32 Bytes speaktest main
> 9 0x100203be0 NSPathStore2 00:00.648.854 • 48 Bytes Foundation +[NSPathStore2 pathStoreWithCharacters:length:]
> 10 0x100203c10 Malloc 512 Bytes 00:00.648.857 • 512 Bytes Foundation +[NSPathStore2 pathStoreWithCharacters:length:]
> 11 0x100203e10 NSPathStore2 00:00.648.870 • 240 Bytes Foundation +[NSPathStore2 pathStoreWithCharacters:length:]
> 12 0x100203f30 Malloc 512 Bytes 00:00.648.885 • 512 Bytes Foundation _NSFileExistsAtPath
> 13 0x100204170 Malloc 112 Bytes 00:00.648.899 • 112 Bytes Foundation -[NSFileManager fileSystemRepresentationWithPath:]
> 14 0x1002041e0 Malloc 128 Bytes 00:00.648.901 • 128 Bytes Foundation +[NSData(NSData) dataWithBytesNoCopy:length:]
> 15 0x100204130 NSConcreteData 00:00.648.905 • 64 Bytes Foundation -[_NSPlaceholderData initWithBytes:length:copy:deallocator:]
> 16 0x100204260 Malloc 256 Bytes 00:00.648.908 • 256 Bytes Foundation -[NSFileManager fileSystemRepresentationWithPath:]
> 17 0x100204360 Malloc 80 Bytes 00:00.648.910 • 80 Bytes Foundation -[NSFileManager fileSystemRepresentationWithPath:]
> 18 0x1002043b0 NSConcreteData 00:00.648.912 • 64 Bytes Foundation -[_NSPlaceholderData initWithBytes:length:copy:deallocator:]
> 19 0x1002043f0 Malloc 976 Bytes 00:00.648.920 • 976 Bytes Foundation -[NSFileManager fileSystemRepresentationWithPath:]
> 20 0x1002047c0 NSConcreteData 00:00.648.922 • 64 Bytes Foundation -[_NSPlaceholderData initWithBytes:length:copy:deallocator:]
> 21 0x1002049c0 Malloc 128 Bytes 00:00.649.161 • 128 Bytes Foundation +[NSPort port]
> 22 0x100204a70 CFMachPort 00:00.649.185 • 144 Bytes Foundation -[NSMachPort initWithMachPort:options:]
> 23 0x100204be0 OS_dispatch_semaphore 00:00.649.192 • 80 Bytes Foundation -[NSMachPort initWithMachPort:options:]
> 24 0x1006070b0 CFString (immutable) 00:02.482.152 • 128 Bytes Foundation -[NSPlaceholderString initWithBytes:length:encoding:]
> 25 0x1006068b0 __NSDictionaryM 00:02.482.157 • 48 Bytes Foundation +[NSTask currentTaskDictionary]
> 26 0x100606ea0 Malloc 64 Bytes 00:02.482.162 • 64 Bytes Foundation +[NSTask currentTaskDictionary]
> 27 0x100606ee0 Malloc 64 Bytes 00:02.482.163 • 64 Bytes Foundation +[NSTask currentTaskDictionary]
> 28 0x100606d00 __NSArrayI 00:02.482.171 • 32 Bytes speaktest main
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Xcode-users mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden