confused about hanging pointer

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

confused about hanging pointer

Ben Coman
Background:
I'm looking into
https://pharo.fogbugz.com/f/cases/19973/DarkTheme-tool-bar-icons

Take for example UITheme>>
   windowMaximizeForm
       "Answer the form to use for the maximize button of a window."
       "self haltOnce."
       ^self forms at: #windowMaximize ifAbsent: [  "self haltOnce"
                 Form extent: 10@10 depth: Display depth]

If I uncomment the top haltOnce, and then right-click on an item in
the bottom toolbar,
a debug window shows up as expected.

After changing the theme, I would expect "forms" to be nil.
But uncommenting only the second haltOnce inside the block,
then changing "System > Settings > Appearance > User interface theme"
to white then back to dark,
and then right-click on an item in the bottom toolbar,
does *not* produce a debug window.

Now upon booting a freshly downloaded 60469 image...
   Pharo3DarkTheme allInstances size "==> 1"
then after changing  System > Settings > Appearance > User interface theme
to white then back to dark...
   Pharo3DarkTheme allInstances size "==> 2"


Its almost like changing themes creating a new instance of Pharo3DarkTheme,
but it doesn't get installed in the right places.  Preliminary check...

"Booted fresh 60469 image. Opened a playground."
Pharo3DarkTheme allInstances collect: [:i | i identityHash -> i
pointersTo size].
    "{748241152->8}"

"Opened System > Settings"
Pharo3DarkTheme allInstances collect: [:i | i identityHash -> i
pointersTo size].
    "{748241152->14}"

"1. Changed Appearance > User interface theme to white then back to dark"
Pharo3DarkTheme allInstances collect: [:i | i identityHash -> i
pointersTo size].
    "{748241152->6. 954809088->12}"

"2. Changed Appearance > User interface theme to white then back to dark"
Pharo3DarkTheme allInstances collect: [:i | i identityHash -> i
pointersTo size].
    "{748241152->6. 954809088->1. 721110784->12}"

"3. Changed Appearance > User interface theme to white then back to dark"
Pharo3DarkTheme allInstances collect: [:i | i identityHash -> i
pointersTo size].
    "{748241152->6. 954809088->1. 721110784->1. 127158784->12}"

"Closed settings window."
Smalltalk garbageCollect.
Pharo3DarkTheme allInstances collect: [:i | i identityHash -> i
pointersTo size].
    "{748241152->6. 127158784->12}"


Pharo3DarkTheme allInstances first pointersTo inspect.
    Pharo3DarkTheme(UITheme)>>createCloseBoxFor:
    Pharo3DarkTheme(UIThemeWatery)>>createCollapseBoxFor:
    Pharo3DarkTheme(UIThemeWatery)>>createExpandBoxFor:
    Pharo3DarkTheme(UITheme)>>createCloseBoxFor:
    Pharo3DarkTheme>>createMenuBoxFor:

For a moment I was confused, by seeing only five items,
but of course the sixth was from the block variable "i".


Question: What I really am confused about is, for example in...
    UITheme>>createCloseBoxFor: aSystemWindow
        "Answer a button for closing the window."
        ^(self
                newCloseControlIn: aSystemWindow
                for: aSystemWindow
                action: [aSystemWindow closeBoxHit]
                help: 'Close this window' translated)
                        extent: aSystemWindow boxExtent

I can't understand where in that method a pointer/reference could
remain held. ???

cheers -ben

Reply | Threaded
Open this post in threaded view
|

Re: confused about hanging pointer

Henrik-Nergaard

Hi Ben,


---------------

Smalltalk garbageCollect.
Pharo3DarkTheme allInstances first pointersTo collect: [ :each | each class ] 
"{ClassVariable. Context. Context. Context. Context. Context. Context. Context. Context. Context. Context}"
---------------


>I can't understand where in that method a pointer/reference could
remain held. ???


The references are held in contexts created by block closures like "[aSystemWindow closeBoxHit]".

These contexts are created because the block closure uses a variable from the outer scope.

The block closures in all the #create...BoxFor: methods is not exectued at once but used as callbacks for buttons and is why you can still see references to an old theme, because the callback is still the same in these buttons.

[aSystemWindow closeBoxHit] could be rewritten to (MessageSend reciever: aSystemWindow selector: #closeBoxHit ) making it easier to GC the old theme when themes are changed.


Best regards,

Henrik



 










Fra: Pharo-dev <[hidden email]> på vegne av Ben Coman <[hidden email]>
Sendt: 24. april 2017 04:50:25
Til: Pharo Development List
Emne: [Pharo-dev] confused about hanging pointer
 
Background:
I'm looking into
https://pharo.fogbugz.com/f/cases/19973/DarkTheme-tool-bar-icons

Take for example UITheme>>
   windowMaximizeForm
       "Answer the form to use for the maximize button of a window."
       "self haltOnce."
       ^self forms at: #windowMaximize ifAbsent: [  "self haltOnce"
                 Form extent: 10@10 depth: Display depth]

If I uncomment the top haltOnce, and then right-click on an item in
the bottom toolbar,
a debug window shows up as expected.

After changing the theme, I would expect "forms" to be nil.
But uncommenting only the second haltOnce inside the block,
then changing "System > Settings > Appearance > User interface theme"
to white then back to dark,
and then right-click on an item in the bottom toolbar,
does *not* produce a debug window.

Now upon booting a freshly downloaded 60469 image...
   Pharo3DarkTheme allInstances size "==> 1"
then after changing  System > Settings > Appearance > User interface theme
to white then back to dark...
   Pharo3DarkTheme allInstances size "==> 2"


Its almost like changing themes creating a new instance of Pharo3DarkTheme,
but it doesn't get installed in the right places.  Preliminary check...

"Booted fresh 60469 image. Opened a playground."
Pharo3DarkTheme allInstances collect: [:i | i identityHash -> i
pointersTo size].
    "{748241152->8}"

"Opened System > Settings"
Pharo3DarkTheme allInstances collect: [:i | i identityHash -> i
pointersTo size].
    "{748241152->14}"

"1. Changed Appearance > User interface theme to white then back to dark"
Pharo3DarkTheme allInstances collect: [:i | i identityHash -> i
pointersTo size].
    "{748241152->6. 954809088->12}"

"2. Changed Appearance > User interface theme to white then back to dark"
Pharo3DarkTheme allInstances collect: [:i | i identityHash -> i
pointersTo size].
    "{748241152->6. 954809088->1. 721110784->12}"

"3. Changed Appearance > User interface theme to white then back to dark"
Pharo3DarkTheme allInstances collect: [:i | i identityHash -> i
pointersTo size].
    "{748241152->6. 954809088->1. 721110784->1. 127158784->12}"

"Closed settings window."
Smalltalk garbageCollect.
Pharo3DarkTheme allInstances collect: [:i | i identityHash -> i
pointersTo size].
    "{748241152->6. 127158784->12}"


Pharo3DarkTheme allInstances first pointersTo inspect.
    Pharo3DarkTheme(UITheme)>>createCloseBoxFor:
    Pharo3DarkTheme(UIThemeWatery)>>createCollapseBoxFor:
    Pharo3DarkTheme(UIThemeWatery)>>createExpandBoxFor:
    Pharo3DarkTheme(UITheme)>>createCloseBoxFor:
    Pharo3DarkTheme>>createMenuBoxFor:

For a moment I was confused, by seeing only five items,
but of course the sixth was from the block variable "i".


Question: What I really am confused about is, for example in...
    UITheme>>createCloseBoxFor: aSystemWindow
        "Answer a button for closing the window."
        ^(self
                newCloseControlIn: aSystemWindow
                for: aSystemWindow
                action: [aSystemWindow closeBoxHit]
                help: 'Close this window' translated)
                        extent: aSystemWindow boxExtent

I can't understand where in that method a pointer/reference could
remain held. ???

cheers -ben