Need to release memory? (On mobile app)
I am trying to create my app using javascript classes. When I create a class instance, do I need to release it's memory allocation when I am done with it?
for example I could have the following code
Titanium.include('mysuperclass.js');
var myinstance = new mysuperclass(parameter);
//do stuff with my instance
// ...
// and then when I am finished:
myinstance = null;
Is the last line necessary? or even correct? does it make any sense or is Titanium taking care of freeing memory?
Thanks a lot,
Regis
3 Answers
-
Accepted Answer
We'll take care of freeing memory. However, generally, in the
app.js
(which is consider the global context), most of the memory is retained during your app. If you want to release memory (such as you do something only on startup), you could wrap in an anonymous function (see below). Windows that use JS urls are also nice since when you close them, you automatically free all associated memory.(function() { var do_something_here; })();
-
Using DDMS i found that Memory allocated to application is get increases as i am navigating screen by screen and after some time it crash application with force close message/Fail to load resources. Even i have remove all objects from window and after that assign null to it. i.e
window.remove(viewname);
viewname=null;
window.close();
window=null.
Please help Me OUT. -
Hi Fernan,
I am also having the same memory issues on Android. See this post for some information/details.
http://developer.appcelerator.com/question/132357/memory-leaks-on-android-but-not-on-ios—very-simple-test-case#comment-115055
I am waiting to see if anyone has a working solution for Android.
Thanks