It's important that you are aware of the memory usage of views you
create within Commerce Cloud Endless Aisle.
- If you are creating a new view that doesn't need to persist for the
life of the application, you need to ensure that you clean up correctly
and monitor the memory of the app for leaks
- When a view is closed, the memory usage of the app should return to
what it was before the view appeared
- Upon logout of the application, the appIndex and any subviews
created are removed (deinit called)
See Managing Memory and Finding Leaks.
The patterns the app uses are implemented in the deinit function:
- Create an exports.deinit function in your controller
- Add $.destroy() at the end of deinit
- Add $.stopListening() if any models are used by the view
- Also use this if calling $.listenTo() in the controller
- Ensure that all parents that create this controller are calling
deinit on this included controller (either with createController or
Require in xml files)
- If using Alloy.Dialog.showCustomDialog, deinit is
automatically called on continueEvent and cancelEvent
- Clean up any Requires done in xml files by calling deinit on those
ids
- Look for any <Require id="view_id" src=".."/> in view xml
file
- Call deinit on that, if needed
- view_id is what you specify
- $.view_id.deinit();
- Look for any createController calls in js file
- Call deinit on that if needed by using a global variable of
$.<id> for the controller and then not having to declare
var
- Look for any <* id="<view>"
on<Eventname>="<function>"> listeners in view xml file
- Call $.<view>.removeEventListener(<eventname>,
<function>);
- Look for any $.listenTo calls
- $.stopListening for those specifically, if you need to outside
of deinit, if you are creating again (function that adds listener is
called more than once)
- Use $.stopListening() to remove all
- Look for any *.addEventListener calls
- *.removeEventListener for those, there is no global remove for
this
- Search for $.<view>.add(…) and then call
removeAllChildren($.<view>) on view that is being added to in
code
- Use removeAllChildren($.<viewid>) to recursively remove
all children
- Clean up table rows that require a deinit
- Look for any uses of reset on a table and the TableViewRow of
that table requires a deinit
- Not all tables require this as they don't have rows with
deinit
- If you call reset, you must deinit the rows before if
the rows require a deinit