swarm-support
[Top][All Lists]
Advanced

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

Re: Using collections


From: glen e. p. ropella
Subject: Re: Using collections
Date: Wed, 15 Jan 1997 17:03:44 -0700

>    - collections only contain references to the objects
>      they contain, correct?

They contain references to the object they contain
plus whatever overhead that's associated with the
type of collection.  They do *not* contain the 
objects themselves.

>    - the following code (from Object2dDisplay.m):
> 
>       -setObjectCollection: (id) objects {
>         objectCollection = objects;
>         return self;
>       }
> 
>      only copies a reference to a collection?
>      (That is, now the Object2dDisplay class and
>      another class somewhere both have a pointer to the
>      same collection, right?)

Right.

>    - What does [MyCollection copy: aZone] do?  Does it
>      just copy a reference to MyCollection or does it
>      create a new set of references to the objects in
>      MyCollection?

I think.... (correct me if I'm wrong)...that

All the collections object seem to make a completely
new collection, which means copying all the pointers
to the objects accounted for by the collection.

In the case of the String collection, a copy actually
allocates space for a new string and duplicates that
string object.  So deallocation of a string will not
affect the copy in any way.

In the case of a List, just the refs are copied.  This
means that if you have two lists that have references
to the same object and you deallocate the object and 
remember to remove it from one list but not the other,
then you'll have a dangling reference.

Array works like String in that it makes an entire
copy of the things in the array.

glen


reply via email to

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