Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variables and memory problem

Status
Not open for further replies.

cadbilbao

Programmer
Apr 9, 2001
233
ES
Hi!

I developed a DLL, and when calling it once, there is no problem.

But if you call it twice, at the second time, there are memory
problems ("instruction xxx makes reference to the memory...").

I suppose that I am 're-working' with my variables, so there
are memory space problems.

I do NOT initilize my variables, nor free memory space or things
like that.

Could anybody explain me how to manage variables and memory space?

Regards,
 
Sounds like a problem I had. I had a class with functions in it that I was exporting. The problem came when I tried to call the exported function but NO class existed. See if your problem lies along these lines

Matt
 
From what I understand, Windows by defualt will keep a DLL in memory even after a program has terminated...Now, I don't know if this is true, but if it is, possibly this is the problem? Maybe you could try freeing the DLL from memory before calling it a second time? By the way, if I'm wrong here, just ignore my jibberjabber ;) Rob
"Programming is like art...It makes me feel like chopping my ear off."
 
The DLL will be kept in memory as long as there are references to it. I mean if I had a program that references let's say rpc40.dll and after my program exits there is no other program using this library WIndows unloads the dlls.

On the other hand if I start my program and a dll called rpc40.dll that has the same signature is already in memory the system will try to give my program a reference to that dll (not always).

I suggest the following:
- put all initialization or freeing variables code in your dll.
- put the suspect code in a try-catch, meaybe you can find some more information
- take care with static variables, members or classes if you have, they are the most susceptible to problems. also the virtual functions.

Hope this helps, s-)

Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
Always initalize your variables, and free the library when you are finished. I can almost guarantee that this is the problem in this case :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top