Solved

Memory leak in app, environment: W2k SP2, Delphi 6 (Pack 2), Oracle 8.1.7.4,DOA 3.4.6.1, OCI 8.1.7.2(4)

Posted on 2002-07-09
17
510 Views
Last Modified: 2010-04-04
I have an application that processing tens of thousands of transactions daily. Application environment: Delphi 6(Pack 2), DOA 3.4.6.1, OCI 8.1.7.4, W2K SP2.
Each transaction is processed by a newly-spawned thread that creates a data module containing a Oracle session and multiple queries. Any given transaction will use 1-3 of the query objects. Sessions are not pooled.
It seem to be leaking several MB per day. I suspect it's related to the transaction volume. A desk check of my code appears clean - all GetMems balanced, no premature Exits, all object allocations seem to be freed.
0
Comment
Question by:YisraelE
  • 8
  • 8
17 Comments
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
Try minimizing and restoring your application. Does this bring back the lost memory?
0
 

Author Comment

by:YisraelE
Comment Utility
Yes, the minimizing of main application form is lowereing the memory usage.

Yisrael.
0
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
Then try calling:

  SetProcessWorkingSetSize(GetCurrentProcess, dword(-1), dword(-1));

This should have the same effect. You shouldn't call it too often, though, since it costs performance. Perhaps call it once per day or something like that.

Regards, Madshi.
0
 

Author Comment

by:YisraelE
Comment Utility
My app is multy-trheaded. Is this workaround will make effect on all threads or I should to call this function from each thread context ?
0
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
Doesn't matter from which thread you call this function, since the working set size is specified per process, not per thread.
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
listening . . .
0
 

Author Comment

by:YisraelE
Comment Utility
I have implemented your suggestion and I saw that the mem usaged was lowered, but the VM Size and Handles grows.
Currently the handles quantity is 1200 and VM Size is 22 MB.
0
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
You didn't talk about handles in your original question, just about memory usage.

The call to SetWorkingProcessSetSize just swaps out the RAM that is currently used by your process. After that call your process' memory usage slowly increases again. That's how it works. The big question is, if you call SetWorkingProcessSetSize once every day, is the memory usage after 2 weeks higher than after 1 week constantly running? If no, everything is fine. If yes, there must be a *real* leak.

If there is a steadily increasing amount of open handles, then something seems to be wrong. But handles have not much to do with memory usage. That are two different things...

Regards, Madshi.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:YisraelE
Comment Utility
Ok, I investigated this issue and saw that the Oracle client DLLs(my app uses these dlls) have memory leaks.
(I used a Memory Sleuth 2.0 for this).
Can you, please, help me to decrease a VM Size.

Thanks,
Yisrael.
0
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
How are you supposed to fix memory leaks in an Oracle client DLL? Do you have the source code?

I guess you will have to look for a new (bugfixed) version. Other than that I have no idea how to help you.

Well, you could automatically restart your process every day (let's say at midnight), but that would mean a few seconds delay.

Regards, Madshi.
0
 

Author Comment

by:YisraelE
Comment Utility
Hello,Madshi.
Thank you for you answers. You helped me to decrease a Mem usage. Do you know about some API procedure that will decrease a VM Size of my app.

Thanks,
Yisrael.
0
 
LVL 20

Accepted Solution

by:
Madshi earned 70 total points
Comment Utility
Sorry, no idea. I'm not even sure what is meant with "VM Size". Where do you get the "VM Size" from?
0
 

Author Comment

by:YisraelE
Comment Utility
The VM Size is a column from Windows Task Manager.
In my original message I refferenced to the following columns of Windows Task Manager: Mem Usage (physical memory size), VM Size (virtual memory size), handles (the number of opened handles).
I also investigated the handles count by using a tool Process Explorer that I downloaded from the site http://www.sysinternals.com/. This tools shows a number of opened handles by application,type of each handle and name of each handle.
I saw an enormous amount of handles of type Event and Semaphore which were opened by my app. I don't use semaphores in my app.I uses about 10-14 Critical Sections and a few mutexes to ensure my thread operations.
My app creates all critical sections and mutexes during initialization process and frees them during finalization process. I have no idia to decrease the number of handles and size of virtual memory.
I have also another strange effect in my app(My app is a server that has a TServerSocket to recieve requests from multiple clients via TCP/IP): I receive a following error from OS "Socket operation on non-socket (10038)" when the number of handles is too large( about 17,000). I checked my app with Memory Sleuth 2.0. It seems that my app has no memory leaks. Can you help me with the investigation of this strange problems: a large amount of handles, huge VM Size and non-socket operation.

Thanks,
Yisrael.
0
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
Ah, my task manager options didn't show those columns.

I think the VM size is the size of all the loaded modules. If I'm right with that guess, there's no way to reduce it. But it shouldn't increase over time then. Does it?

About the handles: There's a limit, I thought it would be gone in NT, but maybe it's not. In win9x the limit is exactly 16KB, which is 16 * 1024. That looks really like 17000. Maybe with sockets, this limit is still valid.

The question is: Who creates all those handles and why does he not release them?

You say you have a TServerSocket, I don't know too much about socket programming, but I guess every incoming request gets its own socket, or am I wrong? Do you release those sockets correctly?

Regards, Madshi.

P.S: Going home now, see you tomorrow...
0
 

Author Comment

by:YisraelE
Comment Utility
Hello,Madshi.

You can see these columns in your Task manager by selecting the follwing TM menu: View/Select Columns ...
I'm using W2k SP2. May be you are using another Windows version ?
0
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
I meant I originally had not turned those columns on. But I did turn them on before writing my previous comment.
0
 

Author Comment

by:YisraelE
Comment Utility
The Oracle patch 8.1.7.4 fixes this memory leak.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now