NSTask objectalloc problem
NSTask objectalloc problem
- Subject: NSTask objectalloc problem
- From: Tom Foutz <email@hidden>
- Date: Wed, 28 Apr 2010 14:16:54 -0400
I am trying to run a back-up type of unix script whenever a file
changes in the directory. However, my implementation, when viewed in
"Instruments" with "ObjectAlloc", demonstrates an ever-increasing
number of living objects.
A problematic dummy version:
##############################################
#import <Foundation/Foundation.h>
void sync() {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// Dummy task is just to use unix /bin/ls command
NSTask *ls;
ls = [[NSTask alloc] init];
[ls setLaunchPath:@"/bin/ls"];
[ls launch];
[ls release];
[pool drain];
}
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int i;
for (i=1; i<=5e4; i++) {
sync();
}
[pool drain];
return 0;
}
##############################################
I found this old message, which mentions fixing the problem by using
an NSThread:
http://lists.apple.com/archives/cocoa-dev/2006/Nov/msg01415.html
However, imagine if my dummy task (ls) took five minutes, and in the
mean time, another change occurs on the directory, I am afraid that
another sync job would be initiated on another thread. Perhaps one
solution would be to keep track of the thread instance, and to not
create another NSThread job if the first had not yet finished?
Thanks!
-- Tom
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden