[Zope-dev] Pointer or reference object

Itamar Shtull-Trauring itamars@ibm.net
Tue, 07 Mar 2000 09:32:41 +0200


Johan Carlsson wrote:

> > def manage_addMirror(self, url, REQUEST=None):
> >     """Add a Mirror
> >     """
> >     ob=REQUEST.resolve_url(url)
> >     id=self._setObject(id, ob)
> >     if REQUEST is not None:
> >         try: u=self.DestinationURL()
> >         except: u=REQUEST['URL1']
> >         REQUEST.RESPONSE.redirect(u+'/manage_main')
> >     return ''
> 
> What happens to the acquisition of this object?
> What happens if the object that this object point at
> gets deleted or moved? (Moved shouldn't be a problem?)

To the best of my knowledge of how pickling (and therefore ZODB) work, this
will work as if you had two references to the object in python, e.g. as if
you had done:

	x = klass()
	a = x

Each one should acquire from its environment correctly, when deleted the
other version will still exist, etc..  There may be other problems, and I
may be wrong.  Consider the following:

>>> import pickle
>>> a = 3              
>>> x = a
>>> l = [a, x]
>>> f = open("pickletest", "w")
>>> pickle.dump(l, f)
>>> f.close() 
>>> f = open("pickletest", "r")
>>> l2 = pickle.load(f)
>>> l2
[3, 3]
>>> del l2[0]
>>> l2
[3]

Of course, the only real way to know is to test it out.

-- 
Itamar S.T.  itamars@ibm.net