diff options
author | Stephan Bergmann <stephan.bergmann@allotropia.de> | 2024-08-30 16:19:10 +0200 |
---|---|---|
committer | Stephan Bergmann <stephan.bergmann@allotropia.de> | 2024-08-31 08:29:23 +0200 |
commit | 91842724235bca73690d67d8084ec7581512d791 (patch) | |
tree | 8c2600fc6bb0c7b03879e3c141c8c54232a0d62e /static | |
parent | 712bddcec53a8f3ef5f70d4d9e9201b186452cf6 (diff) |
Explicitly .delete() type and interface objects in uno.js
These objects use smart proxies, so Embind adds them to a JS finalizer (in JS
runtimes where FinalizationRegistry is available), so it shouldn't be necessary
to manually .delete() them, but Embind then emits "Embind found a leaked C++
instance..." warnings about them, which clutter the JS console.
While it is probably impractical for client code to manually .delete() all such
instances, we can at least explicitly .delete() those that occur in uno.js
itself.
Change-Id: Ia21ca5f0bdb246cc5ea272599befd9a16bc970a8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172661
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
Diffstat (limited to 'static')
-rw-r--r-- | static/emscripten/uno.js | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/static/emscripten/uno.js b/static/emscripten/uno.js index fb634cc63c9d..6591a7441220 100644 --- a/static/emscripten/uno.js +++ b/static/emscripten/uno.js @@ -46,7 +46,10 @@ Module.unoObject = function(interfaces, obj) { obj.impl_interfaces[obj.impl_typemap[i]])); } } - return new Module.uno_Any(Module.uno_Type.Void(), undefined); + const ty = Module.uno_Type.Void(); + const ret = new Module.uno_Any(ty, undefined); + ty.delete(); + return ret; }; obj.acquire = function() { ++obj.impl_refcount; }; obj.release = function() { @@ -59,7 +62,9 @@ Module.unoObject = function(interfaces, obj) { obj.getTypes = function() { const types = new Module.uno_Sequence_type(interfaces.length, Module.uno_Sequence.FromSize); for (let i = 0; i !== interfaces.length; ++i) { - types.set(i, Module.uno_Type.Interface(interfaces[i])); + const type = Module.uno_Type.Interface(interfaces[i]); + types.set(i, type); + type.delete(); } return types; }; @@ -76,23 +81,32 @@ Module.unoObject = function(interfaces, obj) { throw new Error('not a UNO interface type: ' + name); } obj.impl_typemap[name] = impl; - const bases = Module.uno.com.sun.star.reflection.XInterfaceTypeDescription2.query(td) - .getBaseTypes(); + const itd = Module.uno.com.sun.star.reflection.XInterfaceTypeDescription2.query(td); + const bases = itd.getBaseTypes(); + itd.delete(); for (let i = 0; i !== bases.size(); ++i) { walk(bases.get(i), impl); } bases.delete(); } + td.delete(); }; - const tdmAny = Module.getUnoComponentContext().getValueByName( + const ctx = Module.getUnoComponentContext(); + const tdmAny = ctx.getValueByName( '/singletons/com.sun.star.reflection.theTypeDescriptionManager'); - const tdm = Module.uno.com.sun.star.container.XHierarchicalNameAccess.query(tdmAny.get()); + ctx.delete(); + const ifc = tdmAny.get(); + tdmAny.delete(); + const tdm = Module.uno.com.sun.star.container.XHierarchicalNameAccess.query(ifc); + ifc.delete(); interfaces.forEach((i) => { const td = tdm.getByHierarchicalName(i); - walk(Module.uno.com.sun.star.reflection.XTypeDescription.query(td.get()), i); + const ifc = td.get(); td.delete(); + walk(Module.uno.com.sun.star.reflection.XTypeDescription.query(ifc), i); + ifc.delete(); }) - tdmAny.delete(); + tdm.delete(); return Module.uno.com.sun.star.uno.XInterface.reference( obj.impl_interfaces[obj.impl_typemap['com.sun.star.uno.XInterface']]); }; |