discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem with NSAutoreleasePool in GNUstep


From: Richard Frith-Macdonald
Subject: Re: Problem with NSAutoreleasePool in GNUstep
Date: Mon, 3 Dec 2001 17:45:47 +0000

On Monday, December 3, 2001, at 05:17 PM, JP Young wrote:

I not be fully informed on the original issue, but I think the source of
this question has to do with an application (WarmStartServer) that will be encoding a very large list of elements to transfer to another process in one large message. Let's say that the size of the element list we are encoding
is about 50M in memory and we call NSArchiver to encode this. At our
application level, we don't have a loop to put a pool within (though one of some form certainly exists within NSArchiver to walk and encode the list). We are just making a single call with a root object that will cause a lot of encoding to happen and generate temporary memory usage that greatly exceeds
the original size of what we are encoding. Putting a pool around the
encodeRootObject: call will be closing the gate after the memory has been
allocated :-)

I think our choices to work around this problem are:

1. Try putting autorelease pools in the encodeWithCoder: methods of our
objects that are being encoded within the list and see if this solves the
problem. This should work if the majority of the memory allocation is
happening in these methods.

2. Break up the list into smaller portions to encode and send. This may be complicated by the fact that we sometimes want to perform this same encoding and write it to disk instead of send it to another process. It would be much
cleaner, in both cases, to just encode one big blob.

3. Go into the NSArchiver code (or write categories for it) that will use
autorelease pools during the execution of its existing logic.

I doubt if 1 or 3 will work ...

1. unless you have custom objects which create temporary objects during coding,
there probably won't be anything in the autorelease pools to free up.

3. nsarchiver doesn't create any temporary objects for you to release ... so
building in autorelease pools here won't help either.

Generally, archiving of objects is primarily a job of writing a binary representation of those objects into a mutable data object ... the amount of memory needed for coding the objects is the size of that mutable data object, and should be directly proportional
to the number of objects archived.

However ... NSArchiver also handles cross referencing where objects may appear more than once in an archive (making sure it stores them only once), and to do this it must maintain a map of all the objects it has archived. This map table could be very big if all the objects you are archiving are different, but you can't release it during the archiving process. If your archive does not contain cross references, you don't need this feature of NSArchiver, and might be well advised to implement a subclass of NSCoder which does the coding
without the cross-reference management.

Splitting huge archives up appears the easiest option though.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]