Re: Unmanaged resources



Hi, I'm confused about one issue. If a form PInvokes into
unmanaged dll are any resources allocated as a result of the
PInvoke call itself.

A little is allocated for the call itself, but that's it.

I read somewhere that an object which allocates
unmnaged resources needs to be manually disposed.

Any object that allocates unamanaged resources must also free them, as the
GC won't know how to. Typically this is done in the object's finalizer.
It's good practice to implement Dispose on these types of objects, and a
general rule is that if you use an object that implements Dispose, you
should call Dispose when you're done with it.

My current thinking is that a Pinvoke does not allocate an
unmanged resource as a result of the call itself..

Correct.

The unmanged dll may (in my case does and frees them,i've checked with
CodeSnitch).
So as long as any resources in the unmanged code are freed one is ok.

What happens in the Dll stays in the Dll (generally anyway, there are
exceptions, like CeRapiInvoke). If the Dll allocates memory, it should free
it up. Now sometimes that has to happen by an external method call, but
that should be documented.


Is this correct?

Hard to say, as there are exceptions for everything. Generally if you
allocate a resource, you need to deallocate it. If something else allocates
memory, it should clean up after itself and you shouldn't have to care about
it.


--
Chris Tacke
OpenNETCF Consulting
www.opennetcf.com
--



.



Relevant Pages

  • Re: #pragma lib buggers everything up
    ... A lot of the resources are relevant to the static ... a client exe, and I experienced these too, i.e. the exe can't use any ... Have a resource-only DLL, you might say, - yes, I did consider this but the ... > and often on a particular version of the compiler and particular compiler ...
    (microsoft.public.vc.language)
  • Re: Localization of my MFC application
    ... We create a set of resource files for each separate program (.EXE, .DLL, ... My resources are not so large that it makes a big ... > We have an application which has an exe and uses two MFC extension DLLs ...
    (microsoft.public.vc.mfc)
  • Re: Using language DLLs for strings ONLY
    ... CString::LoadString(UINT id, HINSTANCE dll), but that would be too much like blindingly ... Do not consider subclassing CString. ... >I've created a per-language DLL with some string resources and when my ...
    (microsoft.public.vc.mfc)
  • How GC Works
    ... one contains the memory part and other manages the ... unmanaged resources and implement finalize in the second class so that ... allocates large memory as classes implementing finalize method requires ... Sub New ...
    (microsoft.public.dotnet.framework.clr)
  • Garbage Collection
    ... one contains the memory part and other manages the ... unmanaged resources and implement finalize in the second class so that ... allocates large memory as classes implementing finalize method requires ... Sub New ...
    (microsoft.public.dotnet.framework.clr)