Re: [Newbies] Proper object removal

2008-06-04 Thread Norbert Hartl
On Wed, 2008-06-04 at 00:04 -0400, Rob Rothwell wrote:
 Hello,
 
 After much help already, I think I need some training in proper object
 removal.
 
 When my application creates an object and stores it in an
 OrderedCollection, and than wants to delete it, I am trying to do so
 quite explicitly with something like:
 
 DataManagerdeleteSelectedAbstractors
 self selected do: [:each |
 self abstractors remove: each.
 each := nil.
 ]
 
 which removes the object from my application (it's collection), and
 yet when I look for my object in the system with
 

 DataAbstractor allInstances.
 
 I still see the object I removed, even with an explicit Smalltalk
 garbageCollect or garbageCollectMost.  Anything I create just seems to
 hang around forever.
 
 Any help understanding what I need to do to make sure my objects
 really go away when I am done with them would be greatly appreciated!

The objects are still referenced in the collection you get 
from self selected. The line with each := nil is useless
as each is only a temporary variable. I assume that you want
to empty the selected collection as well. you could do

DataManagerdeleteSelectedAbstractors
   self selected copy do: [:each |   
   self abstractors remove: each.
   self selected remove: each.
]

regards,

Norbert

___
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners


Re: [Newbies] Proper object removal

2008-06-04 Thread Rob Rothwell
On Wed, Jun 4, 2008 at 12:45 AM, Herbert König [EMAIL PROTECTED]
wrote:

 if you inspect this you get an inspector on an Array. To the left
 select any entry with a left click (on Windows) and select objects
 pointing to this value. You get another inspector with an array of
 the objects pointing to the object you can't delete.

 Again inspecting one of these objects you can see how it points to
 your original object. This might give you a clue. And manually
 deleting these references (setting them to nil in the inspector) will
 eventually free your original object for garbage collection.


This is helpful...and leads me to explain a little more because I was making
an assumption that might not be correct...

I am writing a little arbitrary data collection application using Squeak and
Aida.  I can build forms with tabbed pages and add various fields, move them
up and down, give them different labels, that whole thing.  In short, I can
create lots of objects within objects within objects.

My main classes are:

DataManager -- Manages a list of DataAbstractors
DataAbstractor -- Manages the DynamicRecordPage(s) (basically groups of
fields)
DynamicRecordPage -- Manages FieldDefinition(s)
DynamicRecord -- Holds the data and handles arbitrary messages based on a
FieldDefinition.

I have been assuming that if I get rid of a DataAbstractor, all it's
underlying objects would just go away as well (Pages and Records).

Do you have to explicitly remove the child objects BEFORE removing a parent
object to ensure that it is removed properly?

If some of the objects you find are WeakArray or such you are in the
 (to me) murky area of finalization and weak references. Squeak dev
 would be the place to ask.


Fortunately, these are all recognizable objects that I would expect!

You don't state the size of your problem. Is it three or is it
 thousands of instances hanging around?.


Well, it is a few right now, but just grows continually as I use it!
Nothing ever goes away, so I figure it will BE thousands if I don't figure
this out.  Every now and then I just save my project, blow it away, garbage
collect, and reload everything.  So far, that's the only way I can seem to
get rid of anything!

I once tried the pointer finder tool but wasn't satisfied with it.

 And the swiki has a page on cleaning up junk.

 RR I still see the object I removed, even with an explicit
 RR Smalltalk garbageCollect or garbageCollectMost.

 RR  Anything I create seems to hang around forever.

 Sometimes saving and reloading an image does a more thorough job than
 garbageCollect. Maybe because of the above mentioned weak references.


Thanks for your help...

Rob
___
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners


Re: [Newbies] Proper object removal

2008-06-04 Thread cdrick
2008/6/4 Rob Rothwell [EMAIL PROTECTED]:

 On Wed, Jun 4, 2008 at 3:55 AM, Norbert Hartl [EMAIL PROTECTED] wrote:

 Hi




 The objects are still referenced in the collection you get
 from self selected. The line with each := nil is useless
 as each is only a temporary variable. I assume that you want
 to empty the selected collection as well. you could do

 DataManagerdeleteSelectedAbstractors
   self selected copy do: [:each |
   self abstractors remove: each.
   self selected remove: each.
 ]


 So...why would I use a copy (self selected copy) in this case?  Is that a
 clue to my misunderstanding?

 Rob



because

self selected do: [:each |
  self selected remove: each ] is to avoid ... as it iterates on the
collection on wich you're removing elements...

Try

aColl:=#(1 2 3) asOrderedCollection.
^aColl do: [:ea | aColl remove ea ]

see here: http://bugs.squeak.org/view.php?id=6937

Cédrick
___
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners


Re: [Newbies] Proper object removal

2008-06-04 Thread Victor Rodriguez


Rob Rothwell-2 wrote:
 
 [snip]
 DataManagerdeleteSelectedAbstractors
   self selected copy do: [:each |
   self abstractors remove: each.
   self selected remove: each.
 ]
 
 So...why would I use a copy (self selected copy) in this case?  Is that a
 clue to my misunderstanding?
 

Because the copy of the collection will live only during the execution of
#do: and thus it won't hang on to references to your objects.

Saludos,

Victor Rodriguez.



 Rob
 
 ___
 Beginners mailing list
 Beginners@lists.squeakfoundation.org
 http://lists.squeakfoundation.org/mailman/listinfo/beginners
 
 

-- 
View this message in context: 
http://www.nabble.com/Proper-object-removal-tp17638745p17645408.html
Sent from the Squeak - Beginners mailing list archive at Nabble.com.

___
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners


Re: [Newbies] Proper object removal

2008-06-03 Thread Herbert König
Hello Rob,


RR After much help already, I think I need some training in proper object 
removal.

RR DataAbstractor allInstances.

if you inspect this you get an inspector on an Array. To the left
select any entry with a left click (on Windows) and select objects
pointing to this value. You get another inspector with an array of
the objects pointing to the object you can't delete.

Again inspecting one of these objects you can see how it points to
your original object. This might give you a clue. And manually
deleting these references (setting them to nil in the inspector) will
eventually free your original object for garbage collection.

If some of the objects you find are WeakArray or such you are in the
(to me) murky area of finalization and weak references. Squeak dev
would be the place to ask.

You don't state the size of your problem. Is it three or is it
thousands of instances hanging around?.

I once tried the pointer finder tool but wasn't satisfied with it.

And the swiki has a page on cleaning up junk.

RR I still see the object I removed, even with an explicit
RR Smalltalk garbageCollect or garbageCollectMost. 

RR  Anything I create seems to hang around forever.

Sometimes saving and reloading an image does a more thorough job than
garbageCollect. Maybe because of the above mentioned weak references.


-- 
Cheers,

Herbert   

___
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners