🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.objective-c
Article #308

Re: Advice on accepting/returning objects vs. copies of objects

#308
From: Lee Sailer
Date: Sat, 12 Dec 1992 19:57
36 lines
1923 bytes
Adam Fedor (fedor@hopper.Colorado.EDU) wrote:
: I think I have an answer to this, but since I'm very new to Obj-C, I thought
: I'd ask:
: 
: Say I have an instance of a class List (myList) that stores a 
: bunch of objects.  If some
: client asks for an object and myList returns it, instead of a copy 
: of the object, this leaves open the possibility that the client may 
: change and/or even free the object without myList knowing about - with
: disasterous consequences.

I would distinguish two cases:

1.  You use a List to store some objects of *yours*  that is, you create
them, and you insert them in the list, and so on.  When you ask the List
to return one of them to you, you just get an id, and that is OK.  If
you are foolish enough to free it, and thus confuse your List object,
that's your problem.  After all, its your program.

2.  Some object that provides you services stores a bunch of object id's
in a List object.  Later, according to the services offered, you retrieve
an object from this List.  If you free this object, you are freeing an
object that "belongs" to someone else, which feels bad to me.  Again,
two cases: a)  You promise not to.  b)  You can, and the List object
needs to always check to see if it has a valid object before it frees
it or returns it.

onward...

BTW--what'd you do?

-- 
Lee Sailer

					- Let's leave my employer
					  out of this, OK?
Technical Details
Message-ID: <Bz5ws6.7sz@hpuerca.atl.hp.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!hpscit.sc.hp.com!hpuerca.atl.hp.com!sailer
References: <1992Dec7.212541.20646@colorado.edu>

Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.objective-c
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!hpscit.sc.hp.com!hpuerca.atl.hp.com!sailer
From: sailer@hpuerca.atl.hp.com (Lee Sailer)
Subject: Re: Advice on accepting/returning objects vs. copies of objects
Message-ID: <Bz5ws6.7sz@hpuerca.atl.hp.com>
Date: Sat, 12 Dec 1992 19:57:41 GMT
Distribution: usa
References: <1992Dec7.212541.20646@colorado.edu>
Organization: Hewlett-Packard NARC Atlanta
X-Newsreader: Tin 1.1.3 PL5
Lines: 36