Thanks a lot for the reply. Following Paul's suggestion, I wrote a
method to make the computations I needed on the agents, so I do not need
EZDistribution anymore.
In case someone might be interested in debugging the memory leak, I have
done some experiments with EZDistribution (and EZBin as well), and the
problem does not seem to be related with dropping the object: I found
that there is a huge memory usage increase even when only *one*
EZDistribution is created, and each agent only updates it.
Specifically, I create a single instance of EZDistribution in
SwarmModel, which can be accessed by each agent via a method call.
Now each agent calls the collection upon which EZDistribution operates,
the agent cleans up the collection and add new agents, updates the
distribution and forget about it. Even in this case, I can get my
program using up to 300mg in a little while.
CODE
in Swarm model (- buildObjects )
somePeople=[List create: [self getZone]];
somePeopleTab=[EZBin createBegin: [self getZone]];
[somePeopleTab setTitle: "stats"];
[somePeopleTab setGraphics:0];
[somePeopleTab setBinCount: 5];
[somePeopleTab setLowerBound: 0];
[somePeopleTab setUpperBound: 5];
[somePeopleTab setCollection: somePeople ];
[somePeopleTab setProbedSelector: M(getTypology) ];
[somePeopleTab createEnd];
//// other code
- getSomePeople {
return somePeople;
}
- getSomePeopleTab {
return somePeopleTab;
}
(In Agent.m)
id observed;
id group;
group=[model getSomePeople];
[group removeAll];
//this fill up "group"
for (i=0; i<10;i++) {
while ([group contains: (observed = [self look])] ) ;
[group addLast:observed];
}
[[model getSomePeopleTab] update]; //if I remove this, no memory
problem occurs. With this line, the program grows (very roughly) about
1mg for each thousand calls .
// other unrelated stuff
Thanks again
marcello
On Tue, 2003-06-03 at 20:35, Paul E Johnson wrote:
I agree that the drop on the EZDistribution object should give all the
memory back, but I don't think most people have tried to use that class
in this way and so, if there is a memory leak, we have not been alerted
to it yet. I found a memory leak, which I still have not solved, in a
method that used probes to retrieve double-valued variables, and if you
are doing that, I expect you could see the same issue.
I think that you should redesign your class so that each agent only
creates one EZDistribution as an instance variable and then use it over
and over. There is no need to create and drop at every time.
The other (better!) possibility is you should find a better way to
collect the information you want. For example, are you just trying to
get a tabulation of how many agents there are in each group? If so,
consider using a method like (off the top of my head, excuse typos)
suppose there is an instance variable
int tabulator[6]; //need 6 because your example shows values from 0 to 5
//not 5 binCount as you have;
and somewhere you initialize that to 0's
Then call a method that does the tabulation. This will be much faster
than creating a big old EZDistribution.
- tabulateDistribution
{
id index = [group begin];
id anObject;
for (anObject=[index next]; [index getLoc == Member];
anObject=[index next])
{
int agentValue = [anObject getTypology];
tabulator[agentValue]++;
}
}
Or, if you just want to calculate an average or standard deviation, you
can do that more easily with EZGraph, I can show you how if you need.
Sorry, gotta run to a meeting.