RE: recovering from EOF exception

Jonathan Rochkind <[email protected]> Wed, 12 Mar 2003 11:32:08 -0600
Newsgroups gmane.comp.web.webobjects.eof
Message-ID <[email protected]>
At 12:06 PM 3/12/2003 -0500, you wrote:
>A good point - even in WOF 4.5 Obj-C, objects in the inserted list will have
>a reference count on them - forgot about that.
>
>However, what do you do about other objects in the EC?  In 4.5, if it's not
>in the inserted, deleted, or updated lists, the EC won't hold a ref count on
>them.  Since the EC in Java obviously has a pointer to the object, I guess
>there's no easy way to free up space on purpose, right?

This has changed through several versions of WO.

In 5.0, an EC had a strong reference to all of it's constituent EOs; an EO 
did not have a strong reference to it's EC. [This created opportunity for a 
common mistake: where people would not keep a reference to an EC they 
manually created, but would keep a reference to an EO in it; the EC would 
get garbage collected, disaster would ensue].

In 5.2, an EC has a strong reference only to EOs on it's 
inserted/updated/deleted lists. Other non-changed EOs, the EC only has a 
WeakReference that won't keep them from getting GC'd. But, in 5.2, an EO 
DOES have a strong reference to it's EC. So an EC won't get garbage 
collected so long as one of it's constituent EOs is around not 
garbage-collectible.

But I'm not sure what you are really asking about. As of 5.2: If you don't 
_need_ the EOs anymore, you should make sure you are not keeping a 
reference to them anywhere. Then they will be garbage collectible, and the 
JRE will garbage collect them at it's leisure.  That's how you 'free up 
space' in Java in general---you simply make sure you don't have any 
(strong) references to objects you don't need hanging around anymore.   The 
EOF design in 5.0 made this not work quite as well as it could, since the 
EC kept a strong reference to all EOs it ever knew about. So you really had 
to make the entire EC garbage-collectible in order to make it's EOs 
garbage-collectible.  But this has been rectified with improved design in 5.2.

--Jonathan


>-----Original Message-----
>From: Jonathan Rochkind [mailto:[email protected]]
>Sent: Wednesday, March 12, 2003 12:04 PM
>To: Anderson, Ken; 'Max Muller '; 'Chuck Hill '
>Subject: RE: recovering from EOF exception
>
>
>Well...  the question is, does the EC keep a reference to the EO?  The
>answer is 'yes', if the EO has changes, and being a newly inserted EO
>counts as 'changes'.  [Prior to 5.2, the answer was 'yes' for all EOs].  So
>the fact that you release your own reference to the EO doesn't matter, the
>EC is still keeping a reference to it, still tracking it, will still try to
>insert it on the next saveChanges().
>
>In general, I find Java's automatic garbage collection very convenient, it
>is very nice not to have to worry about reclaiming your memory---when an
>object is no longer referenced by anything else, it will (eventually, if
>the memory is needed) be reclaimed automatically. That "eventually if the
>memory is needed" is significant though.  You can't count on _when_ the
>object will actually be reclaimed. For instance, there is such a thing as a
>WeakReference in modern Java---a sort of reference that _won't_ keep the
>object from being reclaimed, a 'weak' hold on it.  But all that means is
>that the object referenced _could_ be reclaimed---you can't count on the
>object actually _being_ reclaimed _as soon as_ it is in a position to be.
>It might be reclaimed at any point after that. It might even never be
>reclaimed, if the memory is never needed.  It's up to the JRE.  This can
>make things tricky sometimes; it would be nice if we had even more control
>over these things through Java API, but we do not.  There's no way to
>actually check through API how many outstanding strong/weak references
>there are to an object, for instance.
>
>Hope this helps,
>--Jonathan
>
>At 06:52 AM 3/12/2003 -0500, Anderson, Ken wrote:
> >Gentlemen,
> >
> >I'm still an EOF Objective-C guy, and I would probably just release the EO.
> >Since Java does it's own garbage collection, do you find yourselves working
> >around this type of thing alot?  Sorry for the newbie question, but I'm
> >trying to start to learn the Java side of things, and thought maybe one of
> >you guys could throw some thoughts my way.
> >
> >Thanks,
> >Ken
> >
> >-----Original Message-----
> >From: Max Muller
> >To: Chuck Hill
> >Cc: Jonathan Rochkind; [email protected]
> >Sent: 3/11/03 3:59 PM
> >Subject: Re: recovering from EOF exception
> >
> >Hi Jonathan,
> >         I can confirm that deleteObject() does work. I have had to use
> >this in
> >some strange situations as well.
> >
> >Regards,
> >         Max
> >
> >On Tuesday, March 11, 2003, at 12:55 PM, Chuck Hill wrote:
> >
> > > deleteObject() should do what you want.  And I think you told me
> > > before why
> > > this was happening to you so I won't even ask.  ;-)
> > >
> > >
> > > Chuck
> > >
> > >
> > > At 01:56 PM 11/03/2003 -0600, Jonathan Rochkind wrote:
> > >> Let's say I insertObject a new EO, and then try to saveChanges. Upon
> > >> saveChanges, I get an exception. Let's say I am able to determine
> > >> that this
> > >> is a 'can not insert, duplicate primary key' exception. Let's further
> >
> > >> say
> > >> that I know what I want to do to respond to this---I want to just
> > >> forget
> > >> about that damn EO, pretend I never inserted it, remove it from the
> >EC
> > >> entirely, not try to insert it again.
> > >>
> > >> What's the best way to do this?  What I come up with is calling
> >either
> > >> ec.forgetObject (even though the docs tell me never to invoke this
> > >> directly, it somehow seems appropriate) or simply ec.deleteObject
> > >> (recall
> > >> that this is an object which has NEVER existed in the db; the
> > >> exception
> > >> occured trying to insert it).  But it's possible neither of those
> > >> will be
> > >> sufficient at this point. Also there are all the invalidate/refault
> > >> stuff,
> > >> but that doesn't seem appropriate in this situation with a
> > >> not-succesfully-inserted object, and besides, I try to avoid
> > >> invalidate/refault stuff at all costs myself.
> > >>
> > >> Does anyone have any advice?
> > >>
> > >> --Jonathan
> > >>
> > >> _______________________________________________
> > >> EOF mailing list
> > >> [email protected]
> > >> http://www.omnigroup.com/mailman/listinfo/eof
> > >>
> > >
> > > --
> > >
> > > Chuck Hill                                 [email protected]
> > > Global Village Consulting Inc.
> > > http://www.global-village.net
> > > _______________________________________________
> > > EOF mailing list
> > > [email protected]
> > > http://www.omnigroup.com/mailman/listinfo/eof
> >
> >_______________________________________________
> >EOF mailing list
> >[email protected]
> >http://www.omnigroup.com/mailman/listinfo/eof