Memory leaks in NSTask? (Instruments)
Memory leaks in NSTask? (Instruments)
- Subject: Memory leaks in NSTask? (Instruments)
- From: Bruce Q Hammond <email@hidden>
- Date: Wed, 26 Mar 2014 12:37:56 -0700
On Mar 26, 2014, at 12:00 PM, email@hidden wrote:
Carl. The @autorelasepool is outside the scope of the for(;;) so the system never has an opportunity to release the objects in the body of loop.
--BQ
> Message: 1
> Date: Tue, 25 Mar 2014 17:49:08 -0700
> From: Carl Hoefs <email@hidden>
> To: Xcode Users <email@hidden>
> Subject: Memory leaks in NSTask? (Instruments)
> Message-ID:
> <email@hidden>
> Content-Type: text/plain; charset=windows-1252
>
> 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
_______________________________________________
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