In an app where I use a class to retrieve info from a database, I use the
constructor method _new() to open the connection to the db as follows:

Code snippet:

' Gambas class file
' Name: db.class

Private $db As New Connection

' Contructor
Public Sub _new()
'  Open the connection to the database
  With $db
    .Type = "sqlite"
    .host = Home.User
    .name = "db.sqlite"
  End With
  Try $db.Open
  IF Error THEN PRINT "Cannot Open Database. Error = "; Error.Text
End

The question I have is about releasing $db.

Can I assume that the calling SUB or FUNCTION in the main body where I
instantiated the class 'automagically' closes the database connection and
releases the allocated memory when the instance to the class is destroyed
during the termination of the SUB or FUNCTION, or do I have the add a
destructor in my class like this one:

Code

' Destructor
Public Sub _free()
    $db.Close
End

---
Alain J. Baudrez
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60134071&iu=/4140/ostg.clktrk
_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to