Thread: finalize in LargeObject
Hi Shouldn't there be a protected void finalize() { close(); } in LargeObject.java so that the db resources are released when it is garbage collected or am I missing something? thanks, Philip
Can someone comment on this please? > > Hi > > Shouldn't there be a > > protected void finalize() { > close(); > } > > in LargeObject.java so that the db resources are released when it is > garbage collected or am I missing something? > > thanks, > Philip > > > > > > > ---------------------------(end of broadcast)--------------------------- > TIP 2: you can get off all lists at once with the unregister command > (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) > -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 853-3000 + If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup. | Drexel Hill, Pennsylvania 19026
> From: Bruce Momjian [mailto:pgman@candle.pha.pa.us]
> > Shouldn't there be a
> >
> > protected void finalize() {
> > close();
> > }
> >
> > in LargeObject.java so that the db resources are released when it is
> > garbage collected or am I missing something?
Without knowing the implementation details, I'd at least say that you should never rely on finalizers being run to release resources - they're not event guaranteed to run at all, let alone within a reasonable time.
Cheers ...................... JohnD
------------------------------------------------------------------------
John Dickson - Java developer - PowerPlus Australia
johnd@pplus.com.au Ph 07-3367 0533
------------------------------------------------------------------------
NOTICE - The information in this e-mail and any attachments is confidential and is intended for the addressee only. Reading, copying, disclosure or use by anybody else is not authorised. The contents do not represent the opinion of PowerPlus or any of its affiliates except to the extent that it relates to their official business. If you are not the intended recipient, please delete this message and any attachments and advise the sender by return e-mail.
Virus protection is in place at PowerPlus, however virus protection remains the responsibility of the recipient.
I can't see it hurting, it'll mean that when the object is no longer referenced and garbage collected, the (is it a stream?) will get closed. I would have thought it will only be useful in an error condition where the LO didn't already get 'closed()', as I think close() should occur elsewhere and in the finalize() only as a general safety net. However I haven't looked at the code, or the calling code; Peter M. may shed more light on the subject. Cheers, Joe > -----Original Message----- > From: Bruce Momjian [mailto:pgman@candle.pha.pa.us] > Sent: Wednesday, 16 May 2001 1:51 PM > To: Philip Crotwell > Cc: PostgreSQL jdbc list > Subject: Re: [JDBC] finalize in LargeObject > > > > Can someone comment on this please? > > > > > Hi > > > > Shouldn't there be a > > > > protected void finalize() { > > close(); > > } > > > > in LargeObject.java so that the db resources are released when it is > > garbage collected or am I missing something? > > > > thanks, > > Philip > > > > > > > > > > > > > > ---------------------------(end of > broadcast)--------------------------- > > TIP 2: you can get off all lists at once with the unregister command > > (send "unregister YourEmailAddressHere" to > majordomo@postgresql.org) > > > > -- > Bruce Momjian | http://candle.pha.pa.us > pgman@candle.pha.pa.us | (610) 853-3000 > + If your life is a hard drive, | 830 Blythe Avenue > + Christ can be your backup. | Drexel Hill, > Pennsylvania 19026 > > ---------------------------(end of > broadcast)--------------------------- > TIP 1: subscribe and unsubscribe commands go to > majordomo@postgresql.org >
Hi The reason I suggested that the finializer be there is that when you are using large objects via blobs, there is no way to say "I am done with this blob" and have its resources cleaned up. The only thing you can do is set the reference to null and hope the garbage collector cleans up the blob and closes the connection before the backend hits a resource limit on number of open large objects. IMHO, this is really a deficiency in the Blob definition from sun, but there isn't a whole lot we can do about that. :( My database uses a large number of "small" large objects for seismic data. They are being added and accessed all the time. When I was using straight blobs, I would occasionally get errors that made me think that the back end had too many open large objects, even though I only had a reference to one Blob. I can't remember the exact error message, sorry. I am not sure if the finalize would have helped, but I can't see how it would hurt. I solved the problem by switching to just getBytes calls on the result set, which closes the large object internally, and the errors went away. An alternative would be to change from a "every blob has an open large object" to some sort of blob manager that used a "pool" of open large objects. Then old blobs that were not being used could have their large object connections closed, but the manager could remember "where" they were in case the were accessed again. Perhaps someone familar with the large objects on the back end can comment on whether my "too many open large objects" theory has any basis in fact. In addition, this was back when I was using 7.0, so I don't know if there are any differences with 7.1. thanks, Philip On Wed, 16 May 2001, Dickson, John wrote: > > From: Bruce Momjian [mailto:pgman@candle.pha.pa.us] > > > Shouldn't there be a > > > > > > protected void finalize() { > > > close(); > > > } > > > > > > in LargeObject.java so that the db resources are released when it is > > > garbage collected or am I missing something? > > Without knowing the implementation details, I'd at least say that you should > never rely on finalizers being run to release resources - they're not event > guaranteed to run at all, let alone within a reasonable time. > > Cheers ...................... JohnD > > ------------------------------------------------------------------------ > John Dickson - Java developer - PowerPlus Australia > johnd@pplus.com.au Ph 07-3367 0533 > ------------------------------------------------------------------------ > > > NOTICE - The information in this e-mail and any attachments is confidential > and is intended for the addressee only. Reading, copying, disclosure or use > by anybody else is not authorised. The contents do not represent the opinion > of PowerPlus or any of its affiliates except to the extent that it relates > to their official business. If you are not the intended recipient, please > delete this message and any attachments and advise the sender by return > e-mail. > > Virus protection is in place at PowerPlus, however virus protection remains > the responsibility of the recipient. > > >
I reviewed the jdbc discussion of this addition and it seems correct. Comment added to describe purpose. > > Hi > > Shouldn't there be a > > protected void finalize() { > close(); > } > > in LargeObject.java so that the db resources are released when it is > garbage collected or am I missing something? > > thanks, > Philip > > > > > > > ---------------------------(end of broadcast)--------------------------- > TIP 2: you can get off all lists at once with the unregister command > (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) > -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 853-3000 + If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup. | Drexel Hill, Pennsylvania 19026