Do I have to in Titanium Mobile close results set before creating a new one or will it get "closed" automatically once there is no reference to it?
For example, is something like this secure and memory leak free?
var db = db.open("db_name");
var rs = db.execute("SELECT * FROM table");
while(rs.isValidRow()){ /* working with the resuls... */ }
// I make another select before closing the previous (current) results set
rs = db.execute("SELECT * FROM another_table");
while(rs.isValidRow()){ /* working with the results... */ }
// Once I am completely done I close the RS and DB
rs.close();
db.close();
Or I have to close the Results Set every time a new select is needed.
var db = db.open("db_name");
var rs = db.execute("SELECT * FROM table");
while(rs.isValidRow()){ /* working with the resuls... */ }
// Close RS and then initialize a new one
rs.close();
rs = db.execute("SELECT * FROM another_table");
while(rs.isValidRow()){ /* working with the resuls... */ }
rs.close();
db.close();
According to the documentation http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Database.ResultSet
On the iOS platform, closing the database also closes the result set, that is, you can only access the result set if the database is currently open
This can also be found in the source code of Titanium Mobile (iOS) in the iphone/Classes/TiDatabaseProxy.m
(see on Github)
By looking at the source code (the same file) we can see that TiDatabaseProxy
creates an array which is used to store the results set and then later used to close all of them. (see on Github)
Android looks to however work differently and there are few more platforms so for that reason (and also for the "cleanest" of the code) it is best to close the results set before initialising a new one in other case resources (on different platform) may not get released which will then create a memory leak.