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


[Newbies] Re: Proper object removal

2008-06-04 Thread Klaus D. Witzel

On Wed, 04 Jun 2008 09:55:11 +0200, Norbert Hartl wrote:


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.


Not 100% useless, since temporary variables (and arguments, for that  
matter) survive any attempt, from within the same method, to garbage  
collect them:


{'this ', 'and ', 'that'} collect: [:each | ].
Smalltalk garbageCollect.
{thisContext tempAt: 1} inspect

first line: create some object and make a temp var point to it.
second line: invoke GC.
third line: see what's still pointed to by the temp var.

/Klaus


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] Re: Proper object removal

2008-06-04 Thread Bert Freudenberg

On 04.06.2008, at 10:32, Klaus D. Witzel wrote:


On Wed, 04 Jun 2008 09:55:11 +0200, Norbert Hartl wrote:


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.


Not 100% useless, since temporary variables (and arguments, for that  
matter) survive any attempt, from within the same method, to garbage  
collect them:


{'this ', 'and ', 'that'} collect: [:each | ].
Smalltalk garbageCollect.
{thisContext tempAt: 1} inspect

first line: create some object and make a temp var point to it.
second line: invoke GC.
third line: see what's still pointed to by the temp var.



Yikes. Klaus, please keep the hair-splitting to squeak-dev if possible.

Assigning to a block parameter is just wrong. Setting temps to nil is  
unnecessary in any normal method. If your code actually needs to worry  
about this, then you left the beginner playground.


Rob: Here's a recipe to find out what is keeping your instances from  
being garbage-collected:


http://wiki.squeak.org/squeak/2631

- Bert -


___
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] Re: Proper object removal

2008-06-04 Thread Rob Rothwell
On Wed, Jun 4, 2008 at 6:12 AM, Bert Freudenberg [EMAIL PROTECTED]
wrote:

 Yikes. Klaus, please keep the hair-splitting to squeak-dev if possible.

 Assigning to a block parameter is just wrong. Setting temps to nil is
 unnecessary in any normal method. If your code actually needs to worry about
 this, then you left the beginner playground.


I was hoping that was not the case!  I WANT to be a beginner right now, not
understanding something simple!

Rob: Here's a recipe to find out what is keeping your instances from being
 garbage-collected:

 http://wiki.squeak.org/squeak/2631


Thanks,

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


[Newbies] Re: Proper object removal

2008-06-04 Thread Klaus D. Witzel

On Wed, 04 Jun 2008 12:12:59 +0200, Bert Freudenberg wrote:


On 04.06.2008, at 10:32, Klaus D. Witzel wrote:


On Wed, 04 Jun 2008 09:55:11 +0200, Norbert Hartl wrote:


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.


Not 100% useless, since temporary variables (and arguments, for that  
matter) survive any attempt, from within the same method, to garbage  
collect them:


{'this ', 'and ', 'that'} collect: [:each | ].
Smalltalk garbageCollect.
{thisContext tempAt: 1} inspect

first line: create some object and make a temp var point to it.
second line: invoke GC.
third line: see what's still pointed to by the temp var.



Yikes. Klaus, please keep the hair-splitting to squeak-dev if possible.


Ah. Didn't know that enumerating+removing with a block with argument  
+ GC'ing in the same method, belongs to hair-splitting. Instead, I always  
thought that's one of the reasons that at least one to-be-removed object  
is guaranteed to not go away.


But anyways, thanks for letting me know ;)


Assigning to a block parameter is just wrong.


You better read before you write (the way you most often do indeed ;) then  
you'd find that I didn't write any assignment to anything. Instead, I  
ignored that and pointed to a potential beginner's problem. Sorry you  
didn't like that ;)


Setting temps to nil is unnecessary in any normal method. If your code  
actually needs to worry about this, then you left the beginner  
playground.


And if he does removal+GC+check for success in the same method? I cannot  
see whether someone just copies arbitrary statements given in a response  
to a question, or carefully puts them into separate methods, in his code  
in his .image, now or never ;)


Rob: Here's a recipe to find out what is keeping your instances from  
being garbage-collected:


http://wiki.squeak.org/squeak/2631

- Bert -



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


Re: [Newbies] Re: Proper object removal

2008-06-04 Thread Rob Rothwell
On Wed, Jun 4, 2008 at 8:41 AM, Klaus D. Witzel [EMAIL PROTECTED]
wrote:

 {'this ', 'and ', 'that'} collect: [:each | ].
 Smalltalk garbageCollect.
 {thisContext tempAt: 1} inspect

 first line: create some object and make a temp var point to it.
 second line: invoke GC.
 third line: see what's still pointed to by the temp var.



So...if I do line 1, then line 3, should I see items in the Array, or just
the Array itself.

This is all very interesting, because in my application I am creating lots
of collections of objects maintaining parent/child pointers, and I have
obviously just done it WRONG!

Chasing pointers and objects is showing me that when I remove objects from
my collections, I need to do that all the way down, I think...

Thank you for helping my brain move in the right direction.

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


[Newbies] Re: Proper object removal

2008-06-04 Thread Klaus D. Witzel

On Wed, 04 Jun 2008 15:20:05 +0200, Rob Rothwell wrote:


On Wed, Jun 4, 2008 at 8:41 AM, Klaus D. Witzel wrote:


{'this ', 'and ', 'that'} collect: [:each | ].

Smalltalk garbageCollect.
{thisContext tempAt: 1} inspect

first line: create some object and make a temp var point to it.
second line: invoke GC.
third line: see what's still pointed to by the temp var.





So...if I do line 1, then line 3, should I see items in the Array, or  
just the Array itself.


What you want to see (according to your question about object removal) is  
just the empty array; and what I wanted to point out (without  
hair-splitting ;) is, that when you GC+check this within the same method,  
it *must* fail.


In Smalltalk it's very easy to script the removal+GC+check, for example in  
a workspace or add GC+check temporarily in a debugger session; that was my  
concern.


This is all very interesting, because in my application I am creating  
lots

of collections of objects maintaining parent/child pointers, and I have
obviously just done it WRONG!


A good example for maintaining parent/child objects, which works  
perfectly, is Smalltalk's #addSubclass: #removeSubclass: (both on the  
instance side of Class); when you check these two methods think that  
'superclass' is your parent pointer.


Chasing pointers and objects is showing me that when I remove objects  
from

my collections, I need to do that all the way down, I think...

Thank you for helping my brain move in the right direction.

Rob



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


Re: [Newbies] Re: Proper object removal

2008-06-04 Thread Rob Rothwell
On Wed, Jun 4, 2008 at 9:41 AM, Klaus D. Witzel [EMAIL PROTECTED]
wrote:

 What you want to see (according to your question about object removal) is
 just the empty array; and what I wanted to point out (without hair-splitting
 ;) is, that when you GC+check this within the same method, it *must* fail.


I guess it would have to, wouldn't it?

In Smalltalk it's very easy to script the removal+GC+check, for example in a
 workspace or add GC+check temporarily in a debugger session; that was my
 concern.



 A good example for maintaining parent/child objects, which works perfectly,
 is Smalltalk's #addSubclass: #removeSubclass: (both on the instance side of
 Class); when you check these two methods think that 'superclass' is your
 parent pointer.


Thanks for pointing this out--maybe I can learn something and get this
working properly!

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


Re: [Newbies] Re: Proper object removal

2008-06-04 Thread Bert Freudenberg


On 04.06.2008, at 15:20, Rob Rothwell wrote:

On Wed, Jun 4, 2008 at 8:41 AM, Klaus D. Witzel [EMAIL PROTECTED] 
 wrote:

{'this ', 'and ', 'that'} collect: [:each | ].
Smalltalk garbageCollect.
{thisContext tempAt: 1} inspect

first line: create some object and make a temp var point to it.
second line: invoke GC.
third line: see what's still pointed to by the temp var.


So...if I do line 1, then line 3, should I see items in the Array,  
or just the Array itself.


This is all very interesting, because in my application I am  
creating lots of collections of objects maintaining parent/child  
pointers, and I have obviously just done it WRONG!


Chasing pointers and objects is showing me that when I remove  
objects from my collections, I need to do that all the way down, I  
think...



Normally you do not need to do this all the way down. Say you have a  
tree of objects, where the parent points to its children, and the  
children each back to its parent. Then it is sufficient to remove one  
child to have the whole subtree rooted at the child go away. There is  
no need to delete all the children's children. Also, the back  
pointers do no harm. But it is important that there are no other  
references to these objects - no inspectors, debuggers, etc.


As soon as there is no path from a global object to your object, it  
is subject to garbage collection (which will happen later, not  
immediately). The #allInstances method still finds these unreachable  
objects, because it simply looks at each and every object that was not  
yet gc'ed.


- Bert -


___
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


[Newbies] underscore / left-arrow query

2008-06-04 Thread Kel Graham
hello,

when i first started using squeak a couple of years ago, the assignment
operator was displayed as a left arrow, which i really like. it looks very
clean to my eyes (better to me than the pascal like := syntax).

in my current image, a seaside 2.8-530 image, in workspaces etc, i don't get
my lovely left arrow when I assign variables; just a regular underscore.

is it now considered bad form to use the left arrow, or can I set this in
preferences somewhere such that my underscore is converted to an exciting
left-arrow? if it's bad form or broken, i'll mend my ways.

I tried to search for preference settings, but without joy. Google had an
unreasonably high noise ratio as well.



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


[Newbies] Ubuntu and Squeak

2008-06-04 Thread Rob Rothwell
Ok...so we sort of got Ubuntu running on a server...which VM should I go
get?

(Yes, I am so NOT Linux-enabled at this particular time...)

Thanks!

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


Re: [Newbies] Ubuntu and Squeak

2008-06-04 Thread Michael van der Gulik
On Thu, Jun 5, 2008 at 10:07 AM, Rob Rothwell [EMAIL PROTECTED]
wrote:

 Ok...so we sort of got Ubuntu running on a server...which VM should I go
 get?

 (Yes, I am so NOT Linux-enabled at this particular time...)


Hi Rob.

It depends on your architecture. If you're just running on 32-bit x86, you
can just use the latest Linux VM from http://www.squeak.org/Download. Here's
a direct link, because I'm such a nice guy and my browser is open on it
anyway:

http://ftp.squeak.org/3.10/unix-linux/Squeak-3.10-1.i686-pc-linux-gnu.tar.gz

IIRC there may be a VM that is installable from Ubuntu's package manager.
That would work as well.

If you installed the AMD64 bit version of Ubuntu, then things are a bit
trickier. Then you'll need to look at http://www.squeakvm.org/.

Gulik.

-- 
http://people.squeakfoundation.org/person/mikevdg
http://gulik.pbwiki.com/
___
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners