• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 542
  • Last Modified:

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)

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
YisraelE
Asked:
YisraelE
  • 8
  • 8
1 Solution
 
MadshiCommented:
Try minimizing and restoring your application. Does this bring back the lost memory?
0
 
YisraelEAuthor Commented:
Yes, the minimizing of main application form is lowereing the memory usage.

Yisrael.
0
 
MadshiCommented:
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
YisraelEAuthor Commented:
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
 
MadshiCommented:
Doesn't matter from which thread you call this function, since the working set size is specified per process, not per thread.
0
 
kretzschmarCommented:
listening . . .
0
 
YisraelEAuthor Commented:
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
 
MadshiCommented:
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
 
YisraelEAuthor Commented:
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
 
MadshiCommented:
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
 
YisraelEAuthor Commented:
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
 
MadshiCommented:
Sorry, no idea. I'm not even sure what is meant with "VM Size". Where do you get the "VM Size" from?
0
 
YisraelEAuthor Commented:
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
 
MadshiCommented:
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
 
YisraelEAuthor Commented:
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
 
MadshiCommented:
I meant I originally had not turned those columns on. But I did turn them on before writing my previous comment.
0
 
YisraelEAuthor Commented:
The Oracle patch 8.1.7.4 fixes this memory leak.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 8
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now