[V4Rb 2] VDatabase.Close

Charles Yeomans yeomans at desuetude.com
Wed Jun 1 13:47:35 CDT 2005


On Jun 1, 2005, at 1:29 PM, Ruslan Zasukhin wrote:

> On 6/1/05 7:28 PM, "Charles Yeomans" <yeomans at desuetude.com> wrote:
>
>>> 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.
>
> Not agree Charles.
>
> Because
>
>      db = new VDatabase
>      db = nil
>
> Work with RAM instance of class Vdatabase.
> But Create()/Close() work with file state.
>
> This are 2 quite different operations.
>
> Also I can tell you, that in our C++ sources, we always very carefully 
> split
> code which create INSTANCE of class and which do something else. 
> Mixing of
> such operations always bring your traps.

But constructors and destructors in REALbasic behave differently than 
they do in C++.  In REALbasic, destructors are always called, for 
instance, whether or not the constructor succeeds.    They are 
essentially hooks that allow one to execute some code immediately after 
object creation and immediately before object destruction.

--------------
Charles Yeomans



More information about the Valentina mailing list