Article View: comp.lang.pascal.delphi.misc
Article #303Memory leak receiving events from COM object
From: DonutMan
Date: Sat, 01 Feb 2003 21:50
Date: Sat, 01 Feb 2003 21:50
64 lines
4171 bytes
4171 bytes
I am trying to interface with a Visual Basic OCX (my first mistake)
that exposes a number of events with a varying number of parameters
and parameter types. The OCX is basically a wrapper for an IP client
that allows the parent application to "register" with a central IP
server (a regular EXE) and then pass messages to other applications
already connected to the server using the same OCX. When ApplicationA
sends a message to ApplicationB by calling an OCX method, then
ApplicationB will receive an event with the message data. For my
testing, I have created two applications that use the VB OCX, one in
Delphi and one in Visual Basic. I also have the source code for the
OCX.
At a glance, everything appears to work fine. Both of the
applications successfully register with the IP server, and they can
pass text messages back and forth to each other. However, I noticed
that whenever the Delphi application receives a message from the VB
application, the Delphi app's memory use increases by approximately
4KB for every four messages it receives (according to the Task
Manager). This memory leak does not occur with the Visual Basic
application.
The leak not does not seem to be occurring in the OCX, it seems to be
occurring in the Delphi code that handles the event sink. I placed a
breakpoint at the start of the TEventDispatch.Invoke() method in the
Delphi application, and the memory lost in the leak is allocated
somewhere after the OCX's "RaiseEvent" line, but before controls
reaches the first statement in the Invoke() method shown below.
----------
function TEventDispatch.Invoke(DispID: Integer; const IID: TGUID;
LocaleID: Integer; Flags: Word; var Params;
VarResult, ExcepInfo, ArgErr: Pointer): HResult;
begin
// Breakpoint on the 'if' statement shows memory has already been
allocated
if (DispID >= DISPID_MOUSEUP) and (DispID <= DISPID_CLICK) then
FControl.StandardEvent(DispID, TDispParams(Params)) else
FControl.InvokeEvent(DispID, TDispParams(Params));
Result := S_OK;
end;
----------
I tried using MemProof, and it looks like it found a leak, but the
information was too low-level for me to use effectively (a bunch of
addresses that I don't know what to do with). I was unable to debug
any further because--not being a COM guru--I don't know how control
gets passed to the above Invoke() method. I'm guessing that memory is
being allocated for the Params array and then not being freed, and
maybe I just need to figure out how to free it? Does anyone have any
ideas what might be happening here, or how I might further
troubleshoot this problem? If the VB application keeps sending
messages to the Delphi application, then eventually the PC will run
out of memory and bite the dust. The parameter types for the events
do not seem to make a difference...even if the Delphi application
receives an OCX event that has no parameters, memory is consumed.
If anyone is a glutton for punishment, I'll be glad to e-mail you my
application source code, the OCX, and the IP server executable so you
can watch the problem happen yourself and maybe figure out what in the
world is going on.
Thanks in advance for your help!
Mike Sussman
Technical Details
Message-ID:
<12993ff3.0302011350.16c4caea@posting.google.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!postnews1.google.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fd196,cd6ed6b86109629,start X-Google-Attributes: gidfd196,public X-Google-Thread: 10baee,cd6ed6b86109629,start X-Google-Attributes: gid10baee,public X-Google-ArrivalTime: 2003-02-01 13:50:46 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!postnews1.google.com!not-for-mail From: sussmans3@cox.net (DonutMan) Newsgroups: comp.lang.pascal.delphi.misc,borland.public.delphi.oleautomation Subject: Memory leak receiving events from COM object Date: 1 Feb 2003 13:50:45 -0800 Organization: http://groups.google.com/ Lines: 64 Message-ID: <12993ff3.0302011350.16c4caea@posting.google.com> NNTP-Posting-Host: 68.104.169.90 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1044136245 30787 127.0.0.1 (1 Feb 2003 21:50:46 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 1 Feb 2003 21:50:46 GMT