Large memory use using content providers
I have an app which monitors several content providers such as the calendar, contact list, gmail etc
The app is working fine, but I'm finding that it can be using up to about 70mb of memory. When I look in gingerbread at the memory use the app itself is using around 6-7mb and the rest is the content providers, so for example at the moment:
Android Core App - 16mb - Provider Contacts is in use
Gmail - 36mb - Provider Gmail is in use
Calendar Storage 3.9mb - Provider Calendar is in use
When I start the app up the memory usage is low, but as soon as for example I receive a gmail the memory shoots up. When 开发者_StackOverflow中文版I'm querying the content providers I'm always making sure I close any cursors that are opened.
Is there something else I should be closing that I'm missing? I don't want to unregister the observer as I still want to be monitoring for changes in the future.
It seems like my issue was using multiple cursors within one another. I've no idea why, but once I changed my code to perform a query, store the results in a collection, close the query and then iterate around that collection to perform the lower level query I'm now not seeing the really large memory useage.
I was closing the cursors of each at the earliest point possible with the way the code was written, but this way the query gets closed down sooner.
精彩评论