-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shared_ptr behaviour is different accross Node & Asm.js #59
Comments
There's an undocumented feature (slightly broken in master) for this. It's now fixed in Rationale for the default behavior: On Node.js it's possible for the entire JavaScript app to only hold a single On asm.js this is less practical due to lack of any garbage collection hooks. Since you need to free things manually, it seems safer to free each reference manually rather than free them all at once, possibly including references still in use elsewhere. This means the references aren't entirely equal, since freeing them has a different outcome (each one needs to be freed separately and freeing the same one again does nothing). The |
I've just tried with The folks at Yoga had an interesting point regarding the memory management, tho: maybe it would be interesting to have a way to prevent garbage collection altogether, without using shared_ptrs (which need to be eventually manually released with asm.js). Projects would be able to chose which approach is more suited to their interface. Maybe something like: function makeNode() {
var node = new lib.Node();
lib.preventGarbageCollection(node);
return node;
} Which would be a no-op inside browsers. |
If you allocate an object using Is there any benefit to not using |
I think the main benefit is not having to manually releasing the shared_ptr, and rather trust the user & the library to free the objects when they see it fit. It would be a lower level form of memory management, shared pointers being the higher level with extra safety. |
I suppose that sometimes makes things easier on asm.js but can only be more dangerous on Node.js. It could probably be implemented as a policy parameter added to the For now the easiest way to get that behavior is to wrap the class in JavaScript and instead of calling the C++ constructor, call a static method that calls |
In the following code,
insertChild
takes a shared_ptr by copy, andgetChild
returns a shared_ptr by copy:I get
true
on Node.js, andfalse
on asm.js. I think thatfalse
is the correct behaviour, since it gets harder to know if an object has been released or not if eachshared_ptr
instance is the same on the JS side. It would mean that if a shared_ptr is used across two parts of the application, then each would need to be aware if the other actually still need the pointer to avoid deleting it accidentally.(You can check the issue referenced below for more details about why I needed and how I used shared_ptrs - maybe I've missed something)
The text was updated successfully, but these errors were encountered: