Skip to content

Commit 0f1a574

Browse files
committed
Fix nwjs#6583: Menu and MenuItem leak
1 parent 2cb29c8 commit 0f1a574

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/api/object_manager.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,12 @@ void ObjectManager::OnCallObjectMethod(
137137
const std::string& type,
138138
const std::string& method,
139139
const base::ListValue& arguments) {
140+
#if 0
140141
DLOG(INFO) << "OnCallObjectMethod: object_id:" << object_id
141142
<< " type:" << type
142143
<< " method:" << method
143144
<< " arguments:" << arguments;
144-
145+
#endif
145146
Base* object = GetApiObject(object_id);
146147
if (object)
147148
object->Call(method, arguments, rvh);

src/resources/api_nw_menu.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ function Menu (option) {
2424
privates(this).items = [];
2525
privates(this).option = option;
2626

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

3132
Menu.prototype.__defineGetter__('items', function() {

src/resources/api_nw_menuitem.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,14 @@ function MenuItem(option) {
9797

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

102102
}
103103

104+
MenuItem.prototype._destroy = function () {
105+
menuItems.objs[this.id] = null;
106+
};
107+
104108
util.inherits(MenuItem, EventEmitter);
105109

106110
MenuItem.prototype.handleGetter = function(name) {

0 commit comments

Comments
 (0)