Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-14393] Android: fixed garbage collector crash on views #6887

Merged
merged 2 commits into from
Jun 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions android/modules/ui/src/js/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ exports.bootstrap = function(Titanium) {
require("tab").bootstrap(Titanium);
require("listview").bootstrap(Titanium);
require("webview").bootstrap(Titanium);
require("view").bootstrap(Titanium);

Titanium.invocationAPIs.push({namespace: "UI", api: "createWindow"});
Titanium.invocationAPIs.push({namespace: "UI", api: "createTabGroup"});
Expand Down
42 changes: 42 additions & 0 deletions android/modules/ui/src/js/view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2015 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/

var TAG = "View";

exports.bootstrap = function(Titanium) {

var View = Titanium.UI.View;
var TiWindow = Titanium.TiWindow;

var _add = View.prototype.add;
View.prototype.add = function(child) {

if ((child instanceof TiWindow)) {
throw new Error("Cannot add window/tabGroup to a view.");
}
this._children = this._children || [];
_add.call(this, child);
// The children have to be retained by the view in the Javascript side
// in order to let V8 know the relationship between children and the view.
// Therefore, as long as its window is open, all its children won't be detached
// or garbage collected and V8 will recoganize the closures and retain all
// the related proxies.
this._children.push(child);
}

var _remove = View.prototype.remove;
View.prototype.remove = function(child) {
_remove.call(this, child);

// Remove the child in the Javascript side so it can be detached and garbage collected.
var children = this._children || [];
var childIndex = children.indexOf(child);
if (childIndex != -1) {
children.splice(childIndex, 1);
}
}
};