General discussion

Locked

Page file problems and memory leak

By vipul.patel ·
PROBLEM SUMMARY:

A C# .NET based application at our end has memory leak problem. Application uses COM inter-op to take the services of an ATL ActiveX control. The leak is not being detected. The ATL ActiveX is free from leaks as shown by BoundsChecker 7.0 run with application and ActiveX. But the C# allocations are not probably getting freed.

PROBLEM IN DETAIL:

Work Environment:
Visual C++ 7.0 - .NET, ATL with Visual C++ 7.0, Visual C# .NET, Windows XP.

The said ActiveX controls wraps up the Win32 calls for serial communication. The controls help the Container application to use the multithreaded framework in itself to poll multiple serial ports in real time fashion. The serial ports are connected to industrial automation instruments at other end.

The C# application that uses this ActiveX control via COM inter-op makes calls to this control in separate thread(s). Each C# thread is exclusively dedicated to polling from only one serial port. As the polling for data needs to be in as fast manner as possible, the
thread goes on doing these activities consuming relatively more CPU.

As the application is left running for more than few hours, the memory that has been allocated goes on increasing as indicated by Task Manager of Windows. The team suspects that the memory that has been allocated continuously by this infinite thread loop does never gets freed by C#'s
garbage collection.

HELP SOUGHT:

1.Team will like to know expert comments as to what could be the root cause of memory not getting freed in our C# application.
2.If use of ActiveX via COM inter-op may be adding to this problem or what.
3.If there is any configuration issue of .NET Framework that needs to be done to resolve this issue.
4.Is there any way to flush the virtual memory pagefile.sys file.
5.The way to fix this problem.

This conversation is currently closed to new comments.

1 total post (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by DSR28 In reply to Page file problems and me ...

1. Most likely the GC in .NET is not running fast enough; if you allocate on every thread for every poll and the processor is really busy handling all of this, the Gc may not get called for a very long time. I hate to advise calling Gc.Collect, as you can actually stall the thread while it collects.

C# is not immune to bad programming, so ensure you use global variables when required instead of allocating in tight loops, such as you indicate with each thread. Doing this reduces the allocation burden also. If you cannot, ensure that you dispose of each object (if applicable) at the end of your thread. Have another thread do the garbage collection.

2) The interop and marshallers are pretty good about dispatchable objects and they tend to do a good job at garbage collection, but only if the processor is not exhausted on other operations.

3) None that I can think of

4) pagefile.sys can't be flushed, except by the system kernel Memory manager. Hibernating(only on XP) or rebooting is the best way!

5) hmmm. Hopefully my hints (above) will help.

Back to Web Development Forum
1 total post (Page 1 of 1)  

Related Discussions

Related Forums