Android Question Close ResultSet if declared locally?

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Is there any benefit in closing a resultset if it is only declared locally?
I am guessing resources are freed and the cursor is closed in any case if the Sub has finished.

RBS
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Yes, you should close the ResultSet. It will not be immediately closed when the sub ends. It might be closed when the garbage collector releases its resources.
Does the same apply to other data structures, eg lists, maps, arrays?

RBS
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
Perhaps this should be added to the "code smells" post? Something like "Leaving a local ResultSet open", together with your explanation here? And also point out that the same does not apply to other structures, so people don't go overboard on the practice.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
As long as the ResultSet is open the db engine needs to preserve all kinds of resources
I am with you, you should always close the resultset when done with it. Suppose a resuliset is located in one sub. that same sub is run several times with different filters and the developer does not close the resultset. Since the previous resultset is not overwritten and continues to balloon in size as more filters are run on the same sub. I am thinking that since the resultset is not always closed immediately, it can rob more memory that can be allocated to other resources. Please advise with your expert opinion.
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
I consider leaving an open ResultSet a bug. Still I'm not sure that it deserves its place in the code smells list :)
Yeah, I wasn't sure about it either. But it seems like a thing worthy to mention somewhere. I'm sure lots of people, me included, thought it was just fine leaving an open ResultSet in a local sub. Perhaps it could be added as an error to the IDE linter if it's not closed? (Or, att he very least, added to the intellisense documentation that it always should be closed via code - might be there already, I'm not near B4X at the moment and can't check.)
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Mah! It seems so logical to me, even natural to close it in a sub that... my fingers write it autonomously ?
Isn't it the case that in VBA and VB6 resources of local variables are cleared when the procedure finishes?
So, to me and maybe other users coming from VBA/VB6 that may seem not that logical.

RBS
 
Upvote 0
Top