TiShadow is a great tool for speeding up app development. It allows you to push code to test devices within seconds. But running TiShadow for some time, it will crash. This is because the TiShadow app leaves existing windows open when you push a new bundle of the app. So after some time, you’ll run out of memory.
Update: Not needed anymore now TiShadow cleans up itself.
This behavior is documented and a solution for both plain and Alloy apps is provided by David. However, I’ve made a few improvements to the alloy.jmk
file I like to share:
- No need to alter your
index.js
anymore. It just assumes to find a window as the root view of your index-controller. If you need to do further clean-up, like closing additional windows, just add an event listener to the window’sclose
event. - The code will no longer be injected in production deployments.
- The code will not throw errors anymore when you run it over the simulator instead of TiShadow. Even while they were caught in the original code, the debugger still breaks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
task("post:compile", function(event,logger) { var fs = require("fs"), path = require("path"); if (event.alloyConfig.deployType === 'production') { return; } var existing_bits = 'Alloy.createController("index");' var tishadow_bits = [ 'var index = Alloy.createController("index");', 'if (typeof exports !== 'undefined') {', ' exports.close = function () {', ' index.getView().close();', ' };', '}' ].join("\n"); var appjs = path.join(event.dir.resources, "app.js"); fs.writeFileSync( appjs, fs.readFileSync(appjs).toString().replace(existing_bits, tishadow_bits)); }); |