Hi all,
Ive done the searches etc, and although Ive read many interesting articles
and posts, Im not sure they were relevant to my case:
I am using a simple ActiveX control (the Bloomberg Data Control to be
specific). I use application.Run to execute a method where I create an
instance of the RCW as normal. I also set a few properties and register an
event handler. No problems so far. Events fire, and they contain data which
is consumed.
However, each event seems to eat into memory. Im recieving quite a few
events per second, so this adds up pretty quickly. The Event handler
signature is:
void handle_Data(ref object Security, ref int cookie, ref object Fields, ref
object Data, ref int Status);
so Im not sure what, if anything, I should be freeing towards the end of the
handler. Is it possible to free ref variables? If so, how?
It had been suggested that I could try using an MTAThread, but the app in
this case doesnt seem to return ANY events. Any ideas?
Thanks in advance.
Shak
AlexS - 25 Jun 2004 14:53 GMT
Hi, spammy
I would suggest to profile application at least couple of times to see where
the leaks are. Could be that events are coming too fast for GC and it can't
free memory. As about your call - take a closer look how you use objects
after the call. If any of them implements IDisposable - use Dispose on them
as soon as possible, don't leave this for GC.
MTAThread cannot help here and if ActiveX is not thread-safe will only make
things worse. Maybe that's why you don't see events when you use MTA model.
HTH
Alex
> Hi all,
>
[quoted text clipped - 23 lines]
>
> Shak
spammy - 25 Jun 2004 15:15 GMT
Alex,
Thanks for the reply.
Ive tried leaving the event handler empty - but the memory usage still goes
up, which leaves me to assume that its something "behind the scenes" using
up memory. The event handler passes data via the object arguments:
void handle_Data(ref object Security, ref int cookie, ref object Fields, ref
object Data, ref int Status);
These are normally cast to arrays at runtime. I have a hunch that it is
these items which are not destroyed correctly once the handler has finished
its business. Is there any way I can instruct them to be freed? Perhaps via
a Marshal method call?
Shak
> Hi, spammy
>
[quoted text clipped - 39 lines]
> >
> > Shak
AlexS - 25 Jun 2004 18:04 GMT
I am not sure I got everything right, but something says to me that profiler
would be a best option to proceed. Hunch is not very informative, right? You
can get free one from MS - look for CLR Profiler. Even if it is not the best
of breed in stability, it can help you to find out quickly the source of
leaks. Give it couple of seconds to run profiling your app during suspect
periods and check heap allocations and maybe call graphs before and after.
You can try to null objects after processing them, however if it would
help - big question. You need to find out where exactly you have leaks if at
all. Long calls, recursion, event handling could leave some references
hanging in heap, but once again - without hard data you can only guess,
which is not productive in this situation.
HTH
Alex
> Alex,
>
[quoted text clipped - 65 lines]
> > >
> > > Shak
spammy - 28 Jun 2004 09:47 GMT
alex,
well, i set the objects to null on exit of the application and left it
running all weekend - the memory didnt move much, so im happy with that. i
will profile it anyway (before and after this fix) for academic reasons.
thanks for the help.
Spammy
> I am not sure I got everything right, but something says to me that profiler
> would be a best option to proceed. Hunch is not very informative, right? You
[quoted text clipped - 88 lines]
> > > >
> > > > Shak
AlexS - 25 Jun 2004 14:55 GMT
And one more thing - take a look at
http://msdn.microsoft.com/architecture/default.aspx?pull=/library/en-us/dnpag/ht
ml/scalenet.asp
There is some general guidance what to do with objects and other resources
to make life easier for GC.
HTH
Alex
> Hi all,
>
[quoted text clipped - 23 lines]
>
> Shak