makeFixed/makeWeak

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

makeFixed/makeWeak

Louis LaBrunda
Hi All,

I have a large (around 30k) String or ByteArray used as a TCP/IP input buffer.  I create the buffer and then send it #makeFixed to be sure it doesn't move while being filled.  I suspect these buffers are a source of a memory leak (new buffers are created but not freed).  To correct this I send the buffer #makeWeak when the buffer is no-longer needed.  But #makeWeak errors with: "Primitive failed in: Object>>#makeWeak due to Invalid class in receiver".  This doesn't make any sense as the instance was happy with #makeFixed.

Should I be using something else to release/free the instance?

Lou

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: makeFixed/makeWeak

Seth Berman
Hi Lou,

That's because makeWeak doesn't make sense for non-pointer objects like Strings and ByteArrays.
I think what you are looking for is #onFinalizeDo: that it implemented in Object to have the object put in a weak list that will notify you when the object is about to be freed because weak objects are the last refs to it.
Items that are fixed are not garbage collected.  If you have buffers you are fixing...then you need to retain references to them and reuse them.

-- Seth


On Thursday, July 28, 2016 at 4:30:03 PM UTC-4, Louis LaBrunda wrote:
Hi All,

I have a large (around 30k) String or ByteArray used as a TCP/IP input buffer.  I create the buffer and then send it #makeFixed to be sure it doesn't move while being filled.  I suspect these buffers are a source of a memory leak (new buffers are created but not freed).  To correct this I send the buffer #makeWeak when the buffer is no-longer needed.  But #makeWeak errors with: "Primitive failed in: Object>>#makeWeak due to Invalid class in receiver".  This doesn't make any sense as the instance was happy with #makeFixed.

Should I be using something else to release/free the instance?

Lou

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: makeFixed/makeWeak

Louis LaBrunda
Hi Seth,

On Thursday, July 28, 2016 at 5:25:37 PM UTC-4, Seth Berman wrote:
Hi Lou,

That's because makeWeak doesn't make sense for non-pointer objects like Strings and ByteArrays.
I think what you are looking for is #onFinalizeDo: that it implemented in Object to have the object put in a weak list that will notify you when the object is about to be freed because weak objects are the last refs to it.
Items that are fixed are not garbage collected.  If you have buffers you are fixing...then you need to retain references to them and reuse them.

-- Seth

 I was looking for the method that would un-do the #makeFixed.  It seemed like #makeWeak was a good candidate.  I guess I will have to create a pool of fixed buffers and reuse them.

Thanks Seth.

Lou

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: makeFixed/makeWeak

Louis LaBrunda
Hi All,

To wrap this thread up I thought I would give a little history and the result.

I use Totally Objects SocketSet to do most if not all my TCP/IP work.  Their socket wrapper class contains a buffer (String or ByteArray) that was about 4KBs in size.  For reasons I don't remember (probably speed transferring large amounts of data or something) I upped the buffer to around 32KBs.  From time to time I would experience VM crashes that had something to do with memory or addressing, the reason is still unknown.  It was suggested that maybe a buffer overrun or something like that could be the problem.  I don't think that was the cause but I decided to use #makeFixed to prevent any problems with garbage collection moving the buffer.

Because new buffers are allocated with each new instance of the socket wrapper and new socket wrappers are instantiated after an error, especially an error connecting, dead/unused buffers accumulate in fixed space.  Typically there are only a few buffers and the space is not noticed.  But when an error (like failure to connect) repeats, the waisted space gets large.  Hence, my trying to free them.

But since they can't be freed, I took Seth's suggestion and created a pool (in a class variable) of used and now available buffers and only allocate new ones when needed.  I put them in the pool when the socket is closed.  Not very hard to code, once I realized what needed to be done.

Lou

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.