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
519 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
ID: 7140329
Try minimizing and restoring your application. Does this bring back the lost memory?
0
 

Author Comment

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

Yisrael.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 7140377
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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

Author Comment

by:YisraelE
ID: 7140443
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
ID: 7140492
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
ID: 7140591
listening . . .
0
 

Author Comment

by:YisraelE
ID: 7140622
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
ID: 7140636
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
 

Author Comment

by:YisraelE
ID: 7140653
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
ID: 7140661
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
ID: 7140677
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
ID: 7140688
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
ID: 7140744
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
ID: 7140762
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
ID: 7140778
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
ID: 7142615
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
ID: 7319721
The Oracle patch 8.1.7.4 fixes this memory leak.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

820 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