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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to