5,815,133 Members 38,720 Now Online
XDA Developers Android and Mobile Development Forum

Optimizing memory usage

Tip us?
 
LinuxForce
Old
(Last edited by LinuxForce; 4th July 2014 at 09:15 PM.)
#1  
Junior Member - OP
Thanks Meter 0
Posts: 6
Join Date: Mar 2014
Default Optimizing memory usage

Hi !

I'm developing me first "real" (some minor projects before) app for android. Right now i'm trying to optimize the memory usage, regarding to this I have a question. I hope someone can help me.

I've implemented a foreground service, which also updates some UI-elements via a static reference of the MainActivity.

My question is, what happens if the UI is not visible (i.e. MainActivity is destroyed) ? Are these calls ignored ? Are they using memory ?

Thanks in advance!
 
surlac
Old
#2  
Junior Member
Thanks Meter 1
Posts: 21
Join Date: Feb 2012
You shouldn't keep reference objects with short lifecycle from an object with long lifecycle, unless you carefully manage these references.
To answer your question: UI-elements will be kept in memory till ClassLoader will be destroyed or the references will be nullified.
The Following User Says Thank You to surlac For This Useful Post: [ Click to Expand ]
 
bbish937
Old
#3  
Junior Member
Thanks Meter 0
Posts: 11
Join Date: Jul 2014
Quote:
Originally Posted by LinuxForce View Post
Hi !

I'm developing me first "real" (some minor projects before) app for android. Right now i'm trying to optimize the memory usage, regarding to this I have a question. I hope someone can help me.

I've implemented a foreground service, which also updates some UI-elements via a static reference of the MainActivity.

My question is, what happens if the UI is not visible (i.e. MainActivity is destroyed) ? Are these calls ignored ? Are they using memory ?

Thanks in advance!
Once the activity is destroyed there should be no more running resources, ie. memory usage. If you want to stop other UI-elements such as lingering toasts or dialogs, you can overwrite the onDestroy method to do so.
 
surlac
Old
#4  
Junior Member
Thanks Meter 1
Posts: 21
Join Date: Feb 2012
Quote:
Originally Posted by bbish937 View Post
Once the activity is destroyed there should be no more running resources, ie. memory usage.
What if class has static reference to one of Views, will it be nullified by itself once the Activity destroyed or it will be kept in memory?
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes