Mark,

Your analysis is spot on.  The argument array and any argument objects you
construct are protected by the thread context you request them from until
you either detach the context or tell the context to release the reference.
 This is necessary to prevent any object references you might be
manipulating in your code from getting garbage collected out from under you
before you are done with them.  The same applies to any objects returned by
SendMessage.

On Sun, Aug 26, 2012 at 7:24 PM, Mark Miesfeld <miesf...@gmail.com> wrote:

> Hi Rick,
>
> I realized I might be doing something wrong in ooDialog.   Maybe not
> strictly wrong but using up more memory than I should be.
>
> As you probably know, in Windows, you have the window message
> processing loop.  I do an attach thread when the loop is initialized
> for a dialog and keep the thread context pointer until the loop is
> ended, and then do the detach thread.
>
> During the loop, as window messages come in, if the message is one the
> dialog wants to be notified of, I use the thread context to
> SendMessage directly to the dialog.
>
> Now, for many of these send messages, I construct an argument array,
> of Rexx objects, to send to the dialog.  But, I haven't been doing a
> local release for any of these Rexx objects sent as arguments, or the
> array itself for that matter.
>
> After the SysFileTree discussion, I'm thinking maybe all those objects
> created in the thread context are not being garbage collected until
> the thread context is released.  Should I be doing a local release on
> these objects after the return from the send message?  Also, the
> return object from the SendMessage after  I decode it?
>
> In this snippet of code, c by the way is the thread context pointer here:
>
>
>         pCTvCustomDrawSimple pctvcds =
> (pCTvCustomDrawSimple)c->BufferData(tvcdsBuf);
>         memset(pctvcds, 0, sizeof(CTvCustomDrawSimple));
>
>         pctvcds->drawStage = tvcd->nmcd.dwDrawStage;
>         pctvcds->item      = (HTREEITEM)tvcd->nmcd.dwItemSpec;
>         pctvcds->level     = tvcd->iLevel;
>
>         RexxObjectPtr custDrawSimple =
> c->SendMessage1(TheTvCustomDrawSimpleClass, "NEW", tvcdsBuf);
>         if ( custDrawSimple != NULLOBJECT )
>         {
>             RexxObjectPtr msgReply = c->SendMessage1(pcpbd->rexxSelf,
> methodName, custDrawSimple);
>
> I use a RexxBuffer as the memory backing for a TvCustomDrawSimple
> object and send the object as an argument to a method in the Rexx
> dialog.  I was thinking that the memory would get garbage collected
> because I was using the RexxBuffer and there were no references to the
> custDrawSimple object in any Rexx objects.
>
> But, now I'm thinking maybe I need to do a local release on
> custDrawSimple.  Is that custDrawSimple object protected from garbage
> collection until the thread context is released?  Same thing for the
> msgReply object returned from Rexx, is that also protected from
> garbage collection until the thread context is released?
>
>
Yes, any object you allocate via any API will be protected until you
release them or the context that allocated them goes away.  For something
like a simple method call, you generally don't need to worry about this
because you're not allocating many objects and the context goes away as
soon as the method returns.  For something like message looks, you do need
to perform some housekeeping to keep the garbage from piling up (pun
intended!).

Rick


> Thanks.
>
> --
> Mark Miesfeld
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Oorexx-devel mailing list
> Oorexx-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/oorexx-devel
>
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel

Reply via email to