-
Notifications
You must be signed in to change notification settings - Fork 638
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
createHash memory leak #786
Comments
I think it's because it's instantiated in WASM rather than in JS. It looks like you can call |
For my particular use case, I guess that means that deno_std will need to be a PR that adds the |
Hmm well createHasher returns an anonymous function, so you could add free as a property to the function so it would be available to manually call. |
Actually it looks like this won't work without changes to the hash module itself. The public module function, createHash: https://github.com/denoland/deno_std/blob/main/hash/mod.ts#L34 returns a Hash object: https://github.com/denoland/deno_std/blob/main/hash/_wasm/hash.ts#L19 and the Hash object has a private property called https://github.com/denoland/deno_std/blob/main/hash/_wasm/hash.ts#L24 so if I want to call free() I have to access private properties on a class defined within the _wasm folder, which seems like a hack to me. I don't think this is the way this module was intended to be used. If it is indeed necessary that I must manually free() the hash object, then it should definitely be documented here: https://deno.land/std@0.89.0/hash And, the node/crypto module needs to be patched. Otherwise, it seems like some changes need to be made in the rust code, and I'm afraid I don't know enough about WASM and Rust to be able to do that. |
|
Sounds good, then I will wait for Do you think |
Maybe, we'll see how far we get :) |
wasm-pack limits our ability to configure wasm-bindgen and is no longer necessary as we can use wasm-bindgen-cli directly. This allows us to enable --weakrefs which partially mitigates #786 by using a FinalizationRegistry (currently working in Deno Canary, though not yet on Stable) to free memory in the WASM heap automatically when the corresponding JavaScript wrapper objects are garbage-collected. Co-authored-by: William Perron <hey@wperron.io>
Discovered this because pbkdf2 from node/crypto was leaking memory, but the hash module seems to be the source. This script increases in memory at a rate of 50MB/s on my machine, indefinitely (I stopped it at 1GB):
It appears to happen with any hash, not just sha512.
Verison info
The text was updated successfully, but these errors were encountered: