🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.pascal.delphi.misc
1 messages
1 total messages Started by DonutMan Sat, 01 Feb 2003 21:50
Memory leak receiving events from COM object
#303
Author: DonutMan
Date: Sat, 01 Feb 2003 21:50
64 lines
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads