[V4Rb 2] VDatabase.Close
Charles Yeomans
yeomans at desuetude.com
Wed Jun 1 12:28:02 CDT 2005
On Jun 1, 2005, at 12:03 PM, Ruslan Zasukhin wrote:
> On 6/1/05 5:37 PM, "Charles Yeomans" <yeomans at desuetude.com> wrote:
>
>>>> Is VDatabase.Close called somewhere in a destructor? I recall that
>>>> this was a bit of an issue with V4Rb 1, at least for Windows.
>>>
>>> You mean automatically ?
>>>
>>> Yes kernel defend self from such mistake.
>>>
>>> But still will be good if developer do
>>>
>>> db.close
>>> db = nil
>>
>> I don't see why it is a mistake not to call Close. Indeed, it is a
>> mistake in my opinion for there to be a Close method. Perhaps you've
>> heard of "resource acquisition is initialization" ... :)
>
> What about this:
>
> db = new ...
>
> db.open
> ...
> db.close
>
>
> db.open
> ...
> db.close
>
>
> db = nil
>
>
> As you see each action which allocate resources have pair which
> deallocate
> them.
You could do this; you could just as easily do
db = new VDatabase
db.Open
db = nil
db = new VDatabase
db.Open
db = nil
db = new VDatabase
db.Open
db = nil
My point is that it is correct behavior for VDatabase.Close to be
called in the destructor, and it would be a mistake to require the
developer to call Close explicitly, except say in the example you gave.
As I am sure you know, the idea of "resource acquisition is
initialization" is to use destructors to ensure that resources are
released, and that they are not released while someone is still using
the object.
--------------
Charles Yeomans
More information about the Valentina
mailing list