Skip to content

Commit

Permalink
ensure clean up of box morph
Browse files Browse the repository at this point in the history
llast morph was remaining alive because first and last cells were keeping a reference to target morph, which is not good when you are removing a presenter and keeping alive its parent to future use)
  • Loading branch information
estebanlm committed Jan 24, 2024
1 parent 0503480 commit ffce4ff
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,6 @@ SpAbstractMorphicAdapter >> type: aString [
SpAbstractMorphicAdapter >> unsubscribe [

super unsubscribe.

self presenter hasAnnouncer ifFalse: [ ^ self ].
self presenter announcer
unsubscribe: self widget;
Expand Down
1 change: 1 addition & 0 deletions src/Spec2-Adapters-Morphic/SpMorphicBoxAdapter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ SpMorphicBoxAdapter >> remove: aPresenter [

aPresenter adapter ifNotNil: [ :adapter |
| morph |
adapter unsubscribe.
morph := adapter widget.
startPanel removeMorph: morph.
endPanel removeMorph: morph.
Expand Down
13 changes: 13 additions & 0 deletions src/Spec2-Adapters-Morphic/SpMorphicBoxLayoutCalculator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ SpMorphicBoxLayoutCalculator class >> newProperties: anObject [
{ #category : 'calculating' }
SpMorphicBoxLayoutCalculator >> calculateFor: aMorph in: newBounds [

[ self doCalculateFor: aMorph in: newBounds ]
ensure: [ self cleanUp ]
]

{ #category : 'private' }
SpMorphicBoxLayoutCalculator >> cleanUp [

firstCell := lastCell := nil
]

{ #category : 'calculating' }
SpMorphicBoxLayoutCalculator >> doCalculateFor: aMorph in: newBounds [

self subclassResponsibility
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ SpMorphicBoxLayoutCalculatorLeftToRight >> calculateCellFor: aMorph [
]

{ #category : 'calculating' }
SpMorphicBoxLayoutCalculatorLeftToRight >> calculateFor: aMorph in: newBounds [
SpMorphicBoxLayoutCalculatorLeftToRight >> doCalculateFor: aMorph in: newBounds [
"An optimized left-to-right list layout"
| inset extent posX posY centering extraPerCell cell amount last submorphs |

Expand Down Expand Up @@ -126,6 +126,5 @@ SpMorphicBoxLayoutCalculatorLeftToRight >> calculateFor: aMorph in: newBounds [
width := width + amount ].
cell target layoutInBounds: (posX @ posY extent: width @ height).
posX := posX + width + inset.
cell := cell nextCell ].

cell := cell nextCell ]
]
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ SpMorphicBoxLayoutCalculatorTopToBottom >> calculateCellFor: aMorph [
]

{ #category : 'calculating' }
SpMorphicBoxLayoutCalculatorTopToBottom >> calculateFor: aMorph in: newBounds [
SpMorphicBoxLayoutCalculatorTopToBottom >> doCalculateFor: aMorph in: newBounds [
"An optimized top-to-bottom list layout"
| inset extent posX posY centering extraPerCell cell amount last submorphs |

Expand Down Expand Up @@ -107,7 +107,7 @@ SpMorphicBoxLayoutCalculatorTopToBottom >> calculateFor: aMorph in: newBounds [
number := 0.
extra := last := 0.
cell := firstCell.
[cell == nil] whileFalse:[
[ cell == nil ] whileFalse:[
number := number + 1.
height := cell cellSize.
(extraPerCell > 0 and:[cell vSpaceFill]) ifTrue:[
Expand All @@ -117,6 +117,5 @@ SpMorphicBoxLayoutCalculatorTopToBottom >> calculateFor: aMorph in: newBounds [
].
cell target layoutInBounds: (posX @ posY extent: width @ height).
posY := posY + height + inset.
cell := cell nextCell.
].
cell := cell nextCell ]
]

0 comments on commit ffce4ff

Please sign in to comment.