Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / July 2007

Tip: Looking for answers? Try searching our database.

How to free the memory allocated in unmanged code from managed code?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
m... - 17 Jul 2007 13:49 GMT
Hi,

I am using a COM component which provides a function like
GetBitmapData(out BYTE* pData, out long *pLen), in which it allocates
the memory using "new" and returns the pointer and length of memory
block.

i am calling this functon in C# in following way...
int pImageBuffer = 0;
int len = 0;

m_COMAdapter.GetBitmapData(ref pImageBuffer, out len);
IntPtr ImageData = new IntPtr(pImageBuffer);
//I use IntPtr
//Now I need to free up the memory allocated by GetBitmapData()

I am not sure how i can free up the memory here?

I tried Marshal.FreeCoTaskMem(ImageData), but its not helping and i am
sure if it is the correct way...

thx,
m...
Micky Duncan - 30 Jul 2007 03:50 GMT
Hi,
If your COM object allocates the data then it should be the one that frees
it too. Add a method called FreeBitmapData() or something on the COM object.

This is actually a good practice from the days of c++ DLLs where memory is
allocated and shared amonst the DLL's clients.  Clients don't free the data
but rather the one who allocated it in the first place - the DLL

Cheers,
Micky

> Hi,
>
[quoted text clipped - 19 lines]
> thx,
> m...

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.