I have an application in which I use Cursors to save the data obtained from an SQLite query and on many occasions I forget to close themCursor.close();
What problems can that bring me? Does it consume more RAM memory on the device?
If that were the case, it would compensate me to go through the entire app and close them all, but if it doesn't have benefits, I won't be in a hurry to close them.
I have always read that it is highly recommended to close them since it can cause a memory loss in your application (leak memory).
Although it depends on the method you are using to generate your cursor. If you use the method
managedQuery
(deprecated in API 11) you won't need to use it since it closes it for you automatically. As the Android documentation states:which means that this method will close your cursor at the appropriate time and in case you use the method
stopManagingCursor(Cursor)
(also deprecated in API 11) you do need to close it.As the Android documentation recommends, use
CursorLoader
as a substitution (in case you are using any of the above methods).Imagine an application where you require several DAO operations to read data, if these cursors are not closed the data would remain in memory.
The documentation tells you about the close() method
Closing the cursor releases resources, I think it's the most important benefit which answers your question.