Skip to content

Commit

Permalink
Fix #6583: Menu and MenuItem leak
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerwang committed May 2, 2018
1 parent 2cb29c8 commit 0f1a574
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/api/object_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,12 @@ void ObjectManager::OnCallObjectMethod(
const std::string& type,
const std::string& method,
const base::ListValue& arguments) {
#if 0
DLOG(INFO) << "OnCallObjectMethod: object_id:" << object_id
<< " type:" << type
<< " method:" << method
<< " arguments:" << arguments;

#endif
Base* object = GetApiObject(object_id);
if (object)
object->Call(method, arguments, rvh);
Expand Down
3 changes: 2 additions & 1 deletion src/resources/api_nw_menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ function Menu (option) {
privates(this).items = [];
privates(this).option = option;

var items = privates(this).items;
nw.Obj.create(id, 'Menu', option);
messagingNatives.BindToGC(this, nw.Obj.destroy.bind(undefined, id), -1);
messagingNatives.BindToGC(this, function() { items.forEach(function(element) { element._destroy(); }); nw.Obj.destroy(id); }, -1);
};

Menu.prototype.__defineGetter__('items', function() {
Expand Down
6 changes: 5 additions & 1 deletion src/resources/api_nw_menuitem.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,14 @@ function MenuItem(option) {

if (!option.native)
nw.Obj.create(id, 'MenuItem', option);
messagingNatives.BindToGC(this, nw.Obj.destroy.bind(undefined, id), -1);
messagingNatives.BindToGC(this, function() { nw.Obj.destroy(id); }, -1);

}

MenuItem.prototype._destroy = function () {
menuItems.objs[this.id] = null;
};

util.inherits(MenuItem, EventEmitter);

MenuItem.prototype.handleGetter = function(name) {
Expand Down

0 comments on commit 0f1a574

Please sign in to comment.