Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Android Garbage Collector Eating my Variables in Alloy Controller, can I stop it?

$
0
0

I have a simple controller that is called from another controller which crashes because of Android Garbage Collection. This is the code that crashes:

var options = ['a','b','c','d','e'];
 
var optionsDialogOpts = {
  options:options,
  cancel:options.length-1,
  selectedIndex: 0
};
var dialog1 = Titanium.UI.createOptionDialog(optionsDialogOpts);
var dialog2 = Titanium.UI.createOptionDialog(optionsDialogOpts);
var dialog3 = Titanium.UI.createOptionDialog(optionsDialogOpts);
var dialog4 = Titanium.UI.createOptionDialog(optionsDialogOpts);
var dialog5 = Titanium.UI.createOptionDialog(optionsDialogOpts);
 
function showDialog1() { dialog1.show(); }
function showDialog2() { dialog2.show(); }
function showDialog3() { dialog3.show(); }
function showDialog4() { dialog4.show(); }
function showDialog5() { dialog5.show(); }
Basically when I click on an input field and trigger showDialog, sometimes it crashes if Android has collected the dialogX varible. But if I remove the "var" and change the scope to...
var options = ['a','b','c','d','e'];
 
var optionsDialogOpts = {
  options:options,
  cancel:options.length-1,
  selectedIndex: 0
};
 dialog1 = Titanium.UI.createOptionDialog(optionsDialogOpts);
 dialog2 = Titanium.UI.createOptionDialog(optionsDialogOpts);
 dialog3 = Titanium.UI.createOptionDialog(optionsDialogOpts);
 dialog4 = Titanium.UI.createOptionDialog(optionsDialogOpts);
 dialog5 = Titanium.UI.createOptionDialog(optionsDialogOpts);
 
function showDialog1() { dialog1.show(); }
function showDialog2() { dialog2.show(); }
function showDialog3() { dialog3.show(); }
function showDialog4() { dialog4.show(); }
function showDialog5() { dialog5.show(); }
No garbage collection happens!

My full code is here: https://bitbucket.org/mcpuddin/alloy-error-crash-for-android/src and I'm using GA 3.1.2

Seems like a hack to me; any one else have advice?


Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>