swarm-support
[Top][All Lists]
Advanced

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

Re: object removal from list causing core dump


From: Roger M. Burkhart
Subject: Re: object removal from list causing core dump
Date: Fri, 22 May 1998 08:01:00 -0500

> I'm having a bit of problem with my simulation and was wondering
> whether I'm committing a no-no.
> 
> I have a list that will contain a variable but small number of
> objects.  If I set up the following code bit, I get a seg fault and core
> dump.  Is their something wrong with this:
> 
> index=[MyList begin: scratchZone];
> while((anObject=[index next])){
> 
> // check certain properties of the object and
> // if meets criteria:
> 
>   if(condition)
>       [MyList remove: anObject];
> 
> }

The most likely problem that you keep using the index after you've removed
the member out from under it, not by operating on the index but by removing
it directly from the list.  I don't know if you want to exit from the
loop after you've removed a member or keep going checking for more, but in
either event you should be able to do a simple remove using the index you've
already got, replacing your [MyList remove: anObject]:

  if(condition)
       [index remove];

After you've removed using an index, [index next] will still advance
normally to the next member.


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