is this correct ?

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

is this correct ?

Mariano Martinez Peck
Hi!  Look this peace of code:

| instance |
instance := TestCase new.
Transcript show: TestCase allInstances size; cr.
instance become: 'aString'.
Transcript show: TestCase allInstances size; cr.


The size of TestCase instances is always the same. Although I used become: (and changed to an instance of another class) to one of its instances.

So, my main question is, is this correct ?   Or the message allInstances to TestCase should not take into account the instance I sent the message become:  ?

Thanks in advance.

Mariano


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: is this correct ?

Henrik Sperre Johansen

On Dec 2, 2009, at 10:21 23AM, Mariano Martinez Peck wrote:

> Hi!  Look this peace of code:
>
> | instance |
> instance := TestCase new.
> Transcript show: TestCase allInstances size; cr.
> instance become: 'aString'.
> Transcript show: TestCase allInstances size; cr.
>
>
> The size of TestCase instances is always the same. Although I used become: (and changed to an instance of another class) to one of its instances.
>
> So, my main question is, is this correct ?   Or the message allInstances to TestCase should not take into account the instance I sent the message become:  ?
>
> Thanks in advance.
>
> Mariano
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

I believe so, because become'd objects do not follow special rules compared to common GC.
It appears that neither do becomeForward'ed objects, nor temp variables not accessible outside their scope, though they could in theory.

Cheers,
Henry



_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: is this correct ?

Stéphane Ducasse
In reply to this post by Mariano Martinez Peck
become: changes the pointer pointing to the objects not the object itself.
So I'm not sure that instance should be changed.

If I remember correctly what allinstances does is that it use nextObject to
iterate over the object spaces.

Stef

On Dec 2, 2009, at 10:21 AM, Mariano Martinez Peck wrote:

> Hi!  Look this peace of code:
>
> | instance |
> instance := TestCase new.
> Transcript show: TestCase allInstances size; cr.
> instance become: 'aString'.
> Transcript show: TestCase allInstances size; cr.
>
>
> The size of TestCase instances is always the same. Although I used become: (and changed to an instance of another class) to one of its instances.
>
> So, my main question is, is this correct ?   Or the message allInstances to TestCase should not take into account the instance I sent the message become:  ?
>
> Thanks in advance.
>
> Mariano
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: is this correct ?

Lukas Renggli
#become: swaps the two pointers, so both objects continue to exist.

Use the asymmetric variant #becomeForward: to get rid of an object.

And you probably also need a "Smalltalk garbageCollect" to make the
object really disappear.

Lukas



2009/12/2 Stéphane Ducasse <[hidden email]>:

> become: changes the pointer pointing to the objects not the object itself.
> So I'm not sure that instance should be changed.
>
> If I remember correctly what allinstances does is that it use nextObject to
> iterate over the object spaces.
>
> Stef
>
> On Dec 2, 2009, at 10:21 AM, Mariano Martinez Peck wrote:
>
>> Hi!  Look this peace of code:
>>
>> | instance |
>> instance := TestCase new.
>> Transcript show: TestCase allInstances size; cr.
>> instance become: 'aString'.
>> Transcript show: TestCase allInstances size; cr.
>>
>>
>> The size of TestCase instances is always the same. Although I used become: (and changed to an instance of another class) to one of its instances.
>>
>> So, my main question is, is this correct ?   Or the message allInstances to TestCase should not take into account the instance I sent the message become:  ?
>>
>> Thanks in advance.
>>
>> Mariano
>>
>> _______________________________________________
>> Pharo-project mailing list
>> [hidden email]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>



--
Lukas Renggli
http://www.lukas-renggli.ch

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: is this correct ?

Mariano Martinez Peck
Ok, got it. Thanks for all the explanations!

On Wed, Dec 2, 2009 at 12:27 PM, Lukas Renggli <[hidden email]> wrote:
#become: swaps the two pointers, so both objects continue to exist.

Use the asymmetric variant #becomeForward: to get rid of an object.

And you probably also need a "Smalltalk garbageCollect" to make the
object really disappear.

Lukas



2009/12/2 Stéphane Ducasse <[hidden email]>:
> become: changes the pointer pointing to the objects not the object itself.
> So I'm not sure that instance should be changed.
>
> If I remember correctly what allinstances does is that it use nextObject to
> iterate over the object spaces.
>
> Stef
>
> On Dec 2, 2009, at 10:21 AM, Mariano Martinez Peck wrote:
>
>> Hi!  Look this peace of code:
>>
>> | instance |
>> instance := TestCase new.
>> Transcript show: TestCase allInstances size; cr.
>> instance become: 'aString'.
>> Transcript show: TestCase allInstances size; cr.
>>
>>
>> The size of TestCase instances is always the same. Although I used become: (and changed to an instance of another class) to one of its instances.
>>
>> So, my main question is, is this correct ?   Or the message allInstances to TestCase should not take into account the instance I sent the message become:  ?
>>
>> Thanks in advance.
>>
>> Mariano
>>
>> _______________________________________________
>> Pharo-project mailing list
>> [hidden email]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>



--
Lukas Renggli
http://www.lukas-renggli.ch

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project