-
-
Notifications
You must be signed in to change notification settings - Fork 134
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
[Question] Any method to create a event like DLL_PROCESS_DETACH? #50
Comments
Therefore, the easy way to aggregate control of this manually via Observer pattern etc. (unmanaged / managed side) |
Thank you, this Conari looks interesting, should I close the issue or keep it open for future reference? --Edit, I used the AppDomain.ProcessExit event, he is called but he have a "timeout" to free the memory... if the event exceed this, he is interrupted... (3 secs in my target process, i don't know if this can change) |
Leave it open if your problem still is actual.
|
@marcussacana just noticed your new edit (please note, github will never send notification for edit) I do not recommend to use AppDomain.ProcessExit event because it doesn't give guarantee for this operation. Also, the timeout settings available only for unmanaged api, e.g.: ICLRPolicyManager* clrpm;
if(FAILED(pControl->GetCLRManager(__uuidof(ICLRPolicyManager), (void**)&clrpm))) {
return -1;
}
// https://docs.microsoft.com/en-us/dotnet/framework/unmanaged-api/hosting/eclroperation-enumeration
clrpm->SetTimeout(OPR_ProcessExit, 30000); //30sec Thus, try to implement any your custom manager. I don't know what you do, but for example:
Define a Host side that will manage resources: if clr side is unstable (domain may be destructed in any time without notice the unmanaged side) you should share it from unmanaged for managed side (but it can be implemented vice versa) for any allocation of resources. The managed module can request allocation of resources from unmanaged side and access to this data via pointer to structures etc. Conari also may help to work with this data even without declaration of this structures at all, for example: unmanaged C++ struct TSpecB
{
bool d;
TSpecA* s;
};
struct TSpecA
{
int a;
int b;
};
A->a = 4;
A->b = -8;
B->d = true;
B->s = TSpecA*; Conari (illustration of native raw accessing without declaration): [DllExport]
public static void mypoint(IntPtr ptr)
{
var TSpecBPtr = NativeData
._(ptr)
.t<bool>("d")
.t<IntPtr>("s")
.AlignSizeByMax;
...
dynamic dlr = TSpecBPtr.Raw.Type;
IntPtr addrA = dlr.s;
Assert.AreEqual(true, dlr.d);
// B->A
var TSpecAPtr = NativeData
._(addrA)
.align<Int32>(2, "a", "b");
dynamic s = TSpecAPtr.Raw.Type;
Assert.AreEqual(4, s.a); // B->s->a
Assert.AreEqual(-8, s.b); // B->s->b
... Therefore, even if domain of some this loaded module will be destroyed (unexpectedly for unmanaged side) you can still release it via known IUnmanagedResource methods. |
I closed this issue. Please reopen if this still is actual. About:
You can also look #78 |
I wanna stop a memory leak, no ideia to do this without a event while end the process.
The text was updated successfully, but these errors were encountered: