swarm-support
[Top][All Lists]
Advanced

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

Studying defobj and Zones and thinking about memory leaks


From: Paul Johnson
Subject: Studying defobj and Zones and thinking about memory leaks
Date: Fri, 29 Oct 1999 09:46:56 -0500

In the definedobject/Zone part of Swarmdocs, I see this: 
"Since a new zone always requires that an existing zone be identified,
no new zones could be created unless there were some zones that already
existed. Several such zones are predefined as part of the defobj
library; see predefined zones for a summary."

Where do I find the section "predefined zones"?

That section also says that the getZone method is in the drop protocol
documentation, I think that is not correct?

Partly I'm asking because I'm curious about a comment in the docs that
says it may be faster to just drop a whole Zone than to individually
drop the objects inside it.  I started to wonder "how much faster" but
then I started to think it was also much safer.

The usual Swarm example creates the agents in the model swarm's zone, as
in 
        newAgent=[createBegin Agent: self];
        newAgent=[newAgent createEnd];
But there is a danger of memory leaks using this approach, because if
you drop the newAgent, and don't individually eliminate the objects it
has created, then you cause a leak.

So I wondered, why not just create each agent in its own Zone, something
like

        agentMemoryZone=[Zone create: self];
        newAgent=[createBegin Agent: agentMemoryZone];

And then when I need to drop an agent, I could just ask it what its zone
is, and then drop that, 
        zoneToBeKilled=[newAgent getZone];
        [zoneToBeKilled drop];
As long as everything inside the class agent uses the agentMemoryZone
for space, than all those things will get dumped.  At least that's what
I wondered, and that's why I was wanting to understand more about
getZone and such.  It looks to me from the documentation that getZone
does not allocate any space, it just tells you the Zone in which the
current object lives, right? 

Perhaps I need a lesson in "how much memory is used by each kind of
object" because I expect one criticism of the agentMemoryZone approach
will be that it uses lots and lots of memory because Zones are allocated
in page sized chunks and there might be a waste of memory within each
one.  Not that I really understand what a page is, I admit...

-- 
Paul E. Johnson                       email: address@hidden
Dept. of Political Science            http://lark.cc.ukans.edu/~pauljohn
University of Kansas                  Office: (785) 864-9086
Lawrence, Kansas 66045                FAX: (785) 864-5700

                  ==================================
   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]