Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

Details on .NET memory management requirements/gotchas #72

@avonwyss

Description

@avonwyss

Based on lessons learned from hosting ChakraCore in a larger application, I'd have appreciated if the samples/docs had given some guidance on gotchas related to .NET memory management.

Specifically, I had hard to diagnose and understand problems with access violations, ChakraCore telling me that it was running on the wrong thread, etc. which all came from interop issues with callbacks.

Specifically, the .NET GC was collecting delegates which had been passed to ChakraCore (in my case through JsCreateFunction and JsSetPromiseContinuationCallback), which made it so that all unit tests were running fine but when running in the application with some memory pressure things started go awry.

I ended up adding a layer on top of Native.cs which creates and manages GCHandle (Normal mode, not pinned) instances for all delegates passed into ChakraCore APIs. When a context or a runtime is released, it will automatically release the associated GCHandles. With that all problems vanished...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions