NSLock and AutoreleasePool question
NSLock and AutoreleasePool question
- Subject: NSLock and AutoreleasePool question
- From: Development <email@hidden>
- Date: Tue, 15 Jan 2008 23:05:10 -0700
Ok, I read up on the NSLock and becoming thread safe. My application
is designed to download items and it does this in a loop. Each item
may have several parts so 1 file may consist of a dozen ore more
requests to the server. It also requires I use a number of things that
my reading has told me are not thread safe. Particularly,
NSMutableData and NSMutableString. Now, if I understand what I was
reading and well, I'm not sure I did... When I alter mutable data I
should put a lock around it correct?
[aLock lock];
*alter mutableData*
[aLock unlock];
Is this the correct idea?
Also in each loop I have an NSAutoreleasePool because if I don't this
app will chew all the memory available in seconds. As well as the auto
release pool around the method that is called with
detachNewThreadSelector
This is the problem. I have to have the pools to reclaim memory don't
I? But I keep having crashes and the line I'm crashing at is always a
[autoReleasePool release] call. It may be the one inside the loop, or
the function that was originally detached, but it's always one or the
other. This means I am either not using locks correctly, or the
autorelease pool or both. I have tried locking the thread around the
autoreleasepool release but that did not help. I have also tried the
@synchronize() directive but I may not be using it correctly. I've
tried synchronizing both the various bits of mutable data and the pool
itself before releasing it... Can some one help shed a little light on
this? I can provide code segments if you need to see them but they are
too large to include here.
Thanks.
_______________________________________________
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