Object Instances / Garbage collection

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

Object Instances / Garbage collection

Dmitri Zagidulin
I suspect this might be a general Squeak question, but I want to ask
it here in case Seaside adds some complications or things to consider:

How do I delete object instances (is forcing garbage collection
involved) from the image?

So, for instance, say I have a simple Shopping Cart and Items sort of setup.
I add several Items to the cart, which creates instances of those objects.

And then I want to remove them from the cart, delete them. But they're
still around in the image, inspecting
Item allInstances
still reveals those items which are no longer in the cart.

This sort of thing happens all the time in my web apps (I'm using the
simplest form of persistence - in image, no database or anything,
while prototyping), and I'm wondering how you guys get around that.

~Dmitri
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Object Instances / Garbage collection

Avi  Bryant

On Aug 31, 2006, at 11:26 AM, Dmitri Zagidulin wrote:
>
> This sort of thing happens all the time in my web apps (I'm using the
> simplest form of persistence - in image, no database or anything,
> while prototyping), and I'm wondering how you guys get around that.

They're probably being held onto by the Seaside session, which will  
go away eventually.  Try this:

WARegistry clearAllHandlers.  Smalltalk garbageCollect.

And then check #allInstances again.

Avi
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

RE: Object Instances / Garbage collection

Ramon Leon-5
In reply to this post by Dmitri Zagidulin
> I suspect this might be a general Squeak question, but I want
> to ask it here in case Seaside adds some complications or
> things to consider:
>
> How do I delete object instances (is forcing garbage collection
> involved) from the image?
>
> So, for instance, say I have a simple Shopping Cart and Items
> sort of setup.
> I add several Items to the cart, which creates instances of
> those objects.
>
> And then I want to remove them from the cart, delete them.
> But they're still around in the image, inspecting Item
> allInstances still reveals those items which are no longer in
> the cart.
>
> This sort of thing happens all the time in my web apps (I'm
> using the simplest form of persistence - in image, no
> database or anything, while prototyping), and I'm wondering
> how you guys get around that.
>
> ~Dmitri

You shouldn't really force gc or flush the session caches, you really just
need to change your mindset.  Once you remove them from the cart, forget
about them, they're gone, they'll be gc'd eventually.  Don't use SomeClass
allInstances as if it were a database, it's not.  If you want to keep track
of all of your carts, or items, or whatever, put them in your own collection
or dictionary somewhere, so that when you remove them, they are effectively
deleted.  If you want in image persistence, try something like adding an
accessor on the class side like..

Order class>>allOrders
    ^allOrders ifNil: [allOrders := Dictionary new]

Then you can do stuff like

Transcript show: (Order allOrders at: someId)

Order allOrders do:[:each |
  html text: each asString; break].

Try to forget about the concept of delete, that's a relational concept, it
doesn't really exist in OO.  With transparent persistence, an object is
either referenced, or it isn't, that's all you have to think about.  If you
want to save an object, just put it somewhere like

Order allOrders at: someId put: Order new.

Now it's saved.  If you want to get rid of it, then remove it

Order allOrders removeKey: someId

Or

Order allOrders remove: anOrder

That's it, it's gone.  Don't worry that a transient reference might hang
around for a while, you shouldn't care, it's been removed from your model.

Or maybe you want to consider you SeasideSession as a database, put stuff on
the class side

MySession>>allOrders
    ^self class allOrders

MySession class>>allOrders
    ^allOrders ifNil: [allOrders := Dictionary new]

MySession>>allCustomers
    ^self class allCustomers

MySession class>>allCustomers
    ^allCustomers ifNil: [allCustomers := Dictionary new]

Then from you code it's

self session allOrders, or self session allCustomers.  Just a couple simple
ideas.

_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Object Instances / Garbage collection

Dmitri Zagidulin
Avi:
I tried clearing the session cache amd forcing garbage collect. That helps only a part of the way. There's something else I'm missing.

Ramon:
I agree with your general point, that this is an issue of approach more than anything.
Just like you said, I'm using a collection to keep track of the items. But after they're deleted from the collection,
they're still persisting, and accumulating.

Which leads me to suspect I'm missing something, some kind of references that I'm not releasing to them.
Is there any way to discover which objects are pointing to a particular instance?

And in general, is there no other way to "release" an object for garbage collecting, other than making sure there are no references to it?

On 8/31/06, Ramon Leon <[hidden email]> wrote:
> I suspect this might be a general Squeak question, but I want

> to ask it here in case Seaside adds some complications or
> things to consider:
>
> How do I delete object instances (is forcing garbage collection
> involved) from the image?
>
> So, for instance, say I have a simple Shopping Cart and Items
> sort of setup.
> I add several Items to the cart, which creates instances of
> those objects.
>
> And then I want to remove them from the cart, delete them.
> But they're still around in the image, inspecting Item
> allInstances still reveals those items which are no longer in
> the cart.
>
> This sort of thing happens all the time in my web apps (I'm
> using the simplest form of persistence - in image, no
> database or anything, while prototyping), and I'm wondering
> how you guys get around that.
>
> ~Dmitri

You shouldn't really force gc or flush the session caches, you really just
need to change your mindset.  Once you remove them from the cart, forget
about them, they're gone, they'll be gc'd eventually.  Don't use SomeClass
allInstances as if it were a database, it's not.  If you want to keep track
of all of your carts, or items, or whatever, put them in your own collection
or dictionary somewhere, so that when you remove them, they are effectively
deleted.  If you want in image persistence, try something like adding an
accessor on the class side like..

Order class>>allOrders
    ^allOrders ifNil: [allOrders := Dictionary new]

Then you can do stuff like

Transcript show: (Order allOrders at: someId)

Order allOrders do:[:each |
  html text: each asString; break].

Try to forget about the concept of delete, that's a relational concept, it
doesn't really exist in OO.  With transparent persistence, an object is
either referenced, or it isn't, that's all you have to think about.  If you
want to save an object, just put it somewhere like

Order allOrders at: someId put: Order new.

Now it's saved.  If you want to get rid of it, then remove it

Order allOrders removeKey: someId

Or

Order allOrders remove: anOrder

That's it, it's gone.  Don't worry that a transient reference might hang
around for a while, you shouldn't care, it's been removed from your model.

Or maybe you want to consider you SeasideSession as a database, put stuff on
the class side

MySession>>allOrders
    ^self class allOrders

MySession class>>allOrders
    ^allOrders ifNil: [allOrders := Dictionary new]

MySession>>allCustomers
    ^self class allCustomers

MySession class>>allCustomers
    ^allCustomers ifNil: [allCustomers := Dictionary new]

Then from you code it's

self session allOrders, or self session allCustomers.  Just a couple simple
ideas.

_______________________________________________
Seaside mailing list
[hidden email]
<a href="http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside


_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

RE: Object Instances / Garbage collection

Ramon Leon-5

> And in general, is there no other way to "release" an object
> for garbage collecting, other than making sure there are no
> references to it?

No, there aren't, as far as I know.

PointerFinder on: anObject

will show you what's hanging on to it.

_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside