forked from Remedy-Entertainment/binderoo
-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
.NETPertaining to .NET supportPertaining to .NET supportbinderoo_hostSpecifically for the binderoo_host moduleSpecifically for the binderoo_host modulebugSomething isn't workingSomething isn't working
Description
The basic flow of memory usage in C# goes like this:
- Allocate a Host object
- Call a function which creates an ImportedFunction object stored in a static variale; or allocate a bound object which creates an ImportedClass object
- Do your thing
- Close your program
- Garbage collector finalises whatever it wants first, usually not in reverse order of allocation
- Host is destroyed somewhere, which kills all C++ side allocations and things like memory alloc/dealloc function pointers
- ImportedFunction/Class gets finalised, and accesses bad memory
This is clearly rubbish.
The solution is to force all ImportedFunction/Class objects to finalise when the host finalises, before binderoo_host_destroy is called. The current plan for the solution is to add each ImportedFunction/Class to a WeakReference list inside the Host. This will require making the Host object a singleton - which it is in C++ code anyway so no problem there. When the Host finalises, resolving those weak references and manually invoking Dispose on them will clean up all required C++ handles before the host itself gets finalised.
Metadata
Metadata
Assignees
Labels
.NETPertaining to .NET supportPertaining to .NET supportbinderoo_hostSpecifically for the binderoo_host moduleSpecifically for the binderoo_host modulebugSomething isn't workingSomething isn't working