Memory leaks / lifetime best practices #186
-
Has anyone tested the sample apps for memory leaks? For example, try running the I'm asking because the Emscripten docs strongly recommend explicit delete calls for all classes: https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html#memory-management For example, consider the following code from a starter template: // Tell OpenCascade that we want our shape to get meshed
new oc.BRepMesh_IncrementalMesh_2(shape, 0.1, false, 0.1, false); I think this should actually be: // Tell OpenCascade that we want our shape to get meshed
const incmesh = new oc.BRepMesh_IncrementalMesh_2(shape, 0.1, false, 0.1, false);
incmesh.delete(); |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
You are correct, the example code is currently leaking memory left and right. For some smaller applications, this might not be a real problem (if the ocjs life time is relatively short and/or the amount of leaked memory is small). But generally, you would have to do memory cleanup, like you suggested. The examples / starter templates currently don't do memory cleanup, because I think that makes them easier to read / understand (all the Both OpenCascade / OCCT and Emscripten support SmartPointers (OCCT handle or Using the FinalizationRegistry API might also help with reducing the amount of memory cleanup code you have to maintain. |
Beta Was this translation helpful? Give feedback.
You are correct, the example code is currently leaking memory left and right. For some smaller applications, this might not be a real problem (if the ocjs life time is relatively short and/or the amount of leaked memory is small). But generally, you would have to do memory cleanup, like you suggested.
The examples / starter templates currently don't do memory cleanup, because I think that makes them easier to read / understand (all the
.delete()
calls can lead to very lengthy code). But it might be a good idea to have a documentation page on that situation...Both OpenCascade / OCCT and Emscripten support SmartPointers (OCCT handle or
shared_ptr
). So, there is a chance that the amount of …