swarm-support
[Top][All Lists]
Advanced

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

Re: Temporal Lists


From: Gary Polhill
Subject: Re: Temporal Lists
Date: Tue, 11 Jul 2000 09:51:28 +0100

David Aliaga wrote:
> 
> The question is since the list is a variable inside
> the scope of the method, when it finish , the list
> (and the memory ocupied by it) also dissapear? ( or
> should I explicitily call  something [list drop]?
> 
You should call [list drop].
> 
> By the way Why should we use drop with index when they
> are use temporally.
> 

For the same reason that you should drop your list.
When you do:

-myMethod {
  id myList;
  id myIndex;

... the temporary memory you get allocated is just for
an address. So, on a 32 bit machine you will get 4 bytes
allocated to myList and 4 bytes allocated to myIndex. 
(So variables of type id are really pointers.) When you
do

  myList = [List create: [self getZone]];

or

  myIndex = [myList begin: [self getZone]];

... memory gets allocated to the pointers -- i.e. both
of these methods return pointer to a location in memory
with enough free space to store the given object. You
have to free that memory, because it is dynamically
allocated. All the compiler knows about is the 4 bytes
allocated to each of myList and myIndex to store the
addresses, and this is all that will get freed when
the method finishes. 

If you do not drop myList and myIndex at some point,
you will get memory leaks. This can be a bit tricky,
which is why Swarm has Zones. You can save yourself
a lot of bother trying to work out what to drop where
by creating yourself a Zone, then using that Zone
to store whatever, and then dropping the Zone later
on. Dropping a Zone frees all the memory allocated in
it, so you don't need to individually drop all the 
objects in the Zone.

Sorry if this is a bit unclear...

Gary

-- 

Macaulay Land Use Research Institute, Craigiebuckler, Aberdeen. AB15 8QH
Tel: +44 (0) 1224 318611               Email: address@hidden

                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

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