Shall I close Result Set before creating a new one?

0101

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();
0101

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I close an $ionicPopup before opening a new one?

From Dev

NodeJS close previous server port before creating new server

From Dev

Can I set the schema before creating the EntityManager?

From Dev

Close all open Featherlight windows before opening a new one

From Dev

Twitter bootstrap popover close all before opening a new one

From Dev

Twitter bootstrap popover close all before opening a new one

From Dev

WiX remove default IIS website before creating a new one

From Dev

Python: Checking whether an object already exists before creating a new one

From Dev

Check if user exists in database before creating a new one

From Dev

Shall I create an ArrayBuffer every time or shall I clear a previously created one?

From Dev

Shall I create an ArrayBuffer every time or shall I clear a previously created one?

From Dev

How can i destroy all the childs objects before creating new?

From Dev

VB.Net - when shall I use "New" word?

From Dev

VB.Net - when shall I use "New" word?

From Dev

Set empty value of column before create new one in case

From Dev

Must I close a prepared statement before or after I used the result in PHP

From Dev

Mail server: shall I set up a sub-domain name?

From Dev

Can I use a modified variable without creating a new one in Matlab?

From Dev

How can I overwrite the oldest record instead of creating a new one?

From Dev

How can I overwrite the old record instead of creating a new one?

From Dev

How can I overwrite the oldest record instead of creating a new one?

From Dev

How can I set the value and the datatype when creating a new SqlParameter?

From Dev

Should I remove previous version of software before install new one?

From Dev

How to check existing h2 database before creating a new one

From Dev

From NodeJS to C++ how shall I pass arguments and get the result

From Dev

Close one JFrame before opening another JFrame

From Dev

How do I get the stored procedure result set into temp table without creating temp Table

From Dev

Who shall close Content Provider's cursor?

From Dev

Beego: Creating a new orm before every request?

Related Related

  1. 1

    How do I close an $ionicPopup before opening a new one?

  2. 2

    NodeJS close previous server port before creating new server

  3. 3

    Can I set the schema before creating the EntityManager?

  4. 4

    Close all open Featherlight windows before opening a new one

  5. 5

    Twitter bootstrap popover close all before opening a new one

  6. 6

    Twitter bootstrap popover close all before opening a new one

  7. 7

    WiX remove default IIS website before creating a new one

  8. 8

    Python: Checking whether an object already exists before creating a new one

  9. 9

    Check if user exists in database before creating a new one

  10. 10

    Shall I create an ArrayBuffer every time or shall I clear a previously created one?

  11. 11

    Shall I create an ArrayBuffer every time or shall I clear a previously created one?

  12. 12

    How can i destroy all the childs objects before creating new?

  13. 13

    VB.Net - when shall I use "New" word?

  14. 14

    VB.Net - when shall I use "New" word?

  15. 15

    Set empty value of column before create new one in case

  16. 16

    Must I close a prepared statement before or after I used the result in PHP

  17. 17

    Mail server: shall I set up a sub-domain name?

  18. 18

    Can I use a modified variable without creating a new one in Matlab?

  19. 19

    How can I overwrite the oldest record instead of creating a new one?

  20. 20

    How can I overwrite the old record instead of creating a new one?

  21. 21

    How can I overwrite the oldest record instead of creating a new one?

  22. 22

    How can I set the value and the datatype when creating a new SqlParameter?

  23. 23

    Should I remove previous version of software before install new one?

  24. 24

    How to check existing h2 database before creating a new one

  25. 25

    From NodeJS to C++ how shall I pass arguments and get the result

  26. 26

    Close one JFrame before opening another JFrame

  27. 27

    How do I get the stored procedure result set into temp table without creating temp Table

  28. 28

    Who shall close Content Provider's cursor?

  29. 29

    Beego: Creating a new orm before every request?

HotTag

Archive