Garbage collection (Urgent issue)

G

Guest

How can I make sure that a spicific function location in memory will not
moved , by OS/Garbage collection ?????
The problem is : I'm using a DLL this dll have an call backerror function,
in my Application I made an error function which show the error if occurred
(Message box). I send a reference of my Application error function to DLL
call backerror function.
Now every time an error occur in DLL the DLL call my Application error
function.
This mechanism is working , but after some time some how I receive an
exception ,it looks like the Application error function is not in the same
place. and the DLL can't call it again. How can I make sure my Application
error function will not moved , by OS/Garbage collection ?????
This mechanism used a lot in my work, specially when DLL is a low level
writing in(C++/C) and we use C# for a high level (GUI), we want all the error
be handled by high level (Out put message, logfile , re connect low level
(hardware) ...).
 
T

Tom Shelton

How can I make sure that a spicific function location in memory will not
moved , by OS/Garbage collection ?????
The problem is : I'm using a DLL this dll have an call backerror function,
in my Application I made an error function which show the error if occurred
(Message box). I send a reference of my Application error function to DLL
call backerror function.
Now every time an error occur in DLL the DLL call my Application error
function.
This mechanism is working , but after some time some how I receive an
exception ,it looks like the Application error function is not in the same
place. and the DLL can't call it again. How can I make sure my Application
error function will not moved , by OS/Garbage collection ?????
This mechanism used a lot in my work, specially when DLL is a low level
writing in(C++/C) and we use C# for a high level (GUI), we want all the error
be handled by high level (Out put message, logfile , re connect low level
(hardware) ...).

hmmm... Are you maintaining a reference to the callback delegate that
is passed to the dll? Because if your not, your going to have issues
after a gc :)
 
G

Guest

Yes I maintaining a reference to the callback delegate that is passed to the
dll.
 
B

Bob Powell [MVP]

If both the application and the DLL are written using managed code then you
must be releasing the reference or disposing of something by mistake. GC
might move the objects in memory but the system will update the references
automatically and you won't "loose" one.

If the DLL is not managed code however, which is the case in some of your
application it seems, you may need to consider pinning objects that you pass
to the DLL by pointer/IntPtr to prevent them from moving. See
Marshal.GCHandle and/ or Marshal.UnsafeAddrOfPinnedArrayElement for details.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
B

Bob Powell [MVP]

Is the DLL in C++? Have you tried compiling the source with VS.NET?

Without knowing a lot more about your problem it's hard to advise you.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top