Skip to content

Commit 1ab0b14

Browse files
committed
Don't skip native "dispose" operation for children excluded from layout
When a composite is disposed no individual "dispose" operations are sent to the native client for the children. This is because the native client is already aware of the children and can dispose them directly. However, in case "excludeFromLayout" is set to true the widget is no longer attached to it's parent on the native side. This caused a memory leak since these children effectively become orphans, marked as disposed in JavaScript but still in memory on the native side. Change-Id: Iaa2eead31251afdd0355a2007fb4b313ebcea805
1 parent 0a3f5ff commit 1ab0b14

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/tabris/widgets/Composite.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ export default class Composite extends Widget {
157157
if (this.$children) {
158158
const children = this.$children.concat();
159159
for (let i = 0; i < children.length; i++) {
160-
children[i]._dispose(true);
160+
const skipNative = !children[i].excludeFromLayout;
161+
children[i]._dispose(skipNative);
161162
}
162163
this.$children = undefined;
163164
}

test/tabris/widgets/Widget.test.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,12 +474,19 @@ describe('Widget', function() {
474474
expect(client.calls({op: 'destroy', id: parent.cid}).length).to.equal(1);
475475
});
476476

477-
it('does not DESTROY native children', function() {
477+
it('does not DESTROY native children in layout', function() {
478478
parent.dispose();
479479

480480
expect(client.calls({op: 'destroy', id: child.cid}).length).to.equal(0);
481481
});
482482

483+
it('does DESTROY native children excluded from layout', function() {
484+
child.excludeFromLayout = true;
485+
parent.dispose();
486+
487+
expect(client.calls({op: 'destroy', id: child.cid}).length).to.equal(1);
488+
});
489+
483490
it('notifies parent\'s `removeChild` listener', function() {
484491
const listener = spy();
485492
parent.onRemoveChild(listener);

0 commit comments

Comments
 (0)