tags:

views:

184

answers:

3

My Delphi 7 program uses an OCX to control some hardware. I don't have any sample code so I am working through loading/using/unloading the control correctly. Unfortunately, if I use the hardware and load the OCX, the main process will not completely quit when the application closes.
If I use the hardware, the OCX loads and everything works fine. On the program closing, the OCX doesn't unload properly and my program doesn't close completely. It leaves a small 24 meg footprint in memory that can only be seen in Task Manager. If I rerun the program, everything works perfectly including the hardware. If I use the hardware and then close the program, it leaves another 24 meg footprint. Rinse and repeat. Until I can get the OCX code working correctly, if there anyway I can "force" the unloading of the OCX control for now? Or force the termination of the process?

A: 

An OCX control is like a dll. It unloads one way or the other when the process is terminated. Windows reclaims all memory when a process is closed. Where do you see this memory? Only is this program called Activity Monitor? Could it be that that program is incorrect?

UPDATE: After the new information you gave it is clear it is not about freeing memory, but about a process not being closed/terminated.

This could happen if some threads are still running. The 3rd party control might creat threads and has not terminated them yet. This might be a bug or maybe you have to call some finalize/uninitialize/dispose/close method on the 3rd party control?

Lars Truijens
Windows doesn't reclaim this memory. :)If I call the hardware and the OCX loads, then my program doesn't release all of its memory when it closes. A small amount of memory, @ 24 megs, stays in memory. Sorry about using "Activity Monitor." I meant "Task Manager." I can open Task Manager and close the remaining program there.I'm sorry if this sounds confusing.I run the program, it works perfectly, and it closes. No problem.If I run the program and call the hardware, the ocx loads, but my program doesn't completely unload when I close the program.
Steve
So the process keeps running you mean? It does not actually terminate?
Lars Truijens
Exactly and thank you for the help. I'll try to fit all of this in 600 chars.If I execute the program but don't call the hardware, the process terminates.If I run the program, call the hardware and then close the program, the memory size goes from @ 70 Megs to @ 24 Megs and the process doesn't terminate. I can watch the memory decrease, in task manager, until it hits @ 24 megs.If I run the program 10 times, call the hardware 10 times, and close the program 10 times, I'll have 10 running process with @ 24 Megs each. What is weird is that the program and hardware still works perfectly.
Steve
Maybe it is best if you update your question with this info so others can understand your question better.
Lars Truijens
A: 

Try running the program under the debugger, with breakpoints in all your unit finalization sections and in any OnClose methods you have. If you have a form with no OnClose method, add one. Then watch as the application terminates and see how far you get.

frogb
A: 

Have you tried calling the Windows ExitProcess function?

Jeffrey Hantin