Skip to content

Commit

Permalink
Fixing a memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
JanBliznicenko committed Oct 19, 2024
1 parent 1307ac8 commit 3dad350
Show file tree
Hide file tree
Showing 33 changed files with 442 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ OPAbstractElementControllerTest >> testRemoveController [
self
assertCollection: diagramController canvas shapes
includesAll: { controller roassalShape }.
controller removeController.
controller removeControllerAndDiagramElement.
self
should: [ diagramController controllerForModel: model ]
raise: NotFound.
Expand Down
23 changes: 8 additions & 15 deletions repository/OpenPonk-Core/OPBoundary.class.st
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
Class {
#name : 'OPBoundary',
#superclass : 'OPDiagramOnlyShape',
#traits : 'OPTResizableFigureWithText',
#classTraits : 'OPTResizableFigureWithText classTrait',
#superclass : 'OPDiagramOnlyShapeWithText',
#instVars : [
'name',
'positionOfMainRelativeToDragBoxes',
'dragBoxUpdateBlocks',
'dragBoxes'
'name'
],
#category : 'OpenPonk-Core-CommonElements',
#package : 'OpenPonk-Core',
Expand Down Expand Up @@ -41,8 +36,13 @@ OPBoundary >> defaultWidth [

{ #category : 'initialization' }
OPBoundary >> initialize [

super initialize.
name := ''
name := ''.
self
when: OPElementTextAttributeChanged
send: #updateRenderFromSelf
to: self
]

{ #category : 'accessing' }
Expand Down Expand Up @@ -78,13 +78,6 @@ OPBoundary >> renderBasicShape [
yourself
]

{ #category : 'creating - subelements' }
OPBoundary >> renderShapeDetails [

super renderShapeDetails.
self renderLabel
]

{ #category : 'creating - subelements' }
OPBoundary >> selectableInteraction [

Expand Down
11 changes: 0 additions & 11 deletions repository/OpenPonk-Core/OPBoundaryController.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,3 @@ OPBoundaryController >> diagramElementClass [

^ OPBoundary
]

{ #category : 'construction' }
OPBoundaryController >> renderDiagramElement [

super renderDiagramElement.
diagramElement announcer
when: OPElementTextAttributeChanged
do: [ diagramElement updateRenderFromSelf ]
for: self.
^ self roassalShape
]
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ OPCommonElementController >> createModelIn: aParentModel [
{ #category : 'accessing' }
OPCommonElementController >> ensureDiagramElement [

diagramElement ifNil: [ self createDiagramElement ].
diagramElement ifNotExists: [ self createDiagramElement ].
^ diagramElement
]

Expand Down
66 changes: 46 additions & 20 deletions repository/OpenPonk-Core/OPController.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ OPController >> diagramController: aDiagramController [
{ #category : 'accessing' }
OPController >> diagramElement [

^ diagramElement
^ diagramElement ifNil: [ diagramElement := OPNoShape new ]
]

{ #category : 'accessing' }
Expand All @@ -125,7 +125,7 @@ OPController >> elementsToShowInside [
{ #category : 'accessing' }
OPController >> ensureDiagramElement [

self assert: diagramElement isNotNil.
self assert: self diagramElement exists.
diagramElement modelElement: self model.
^ diagramElement
]
Expand All @@ -149,15 +149,13 @@ OPController >> hideSelectionFeedback [
{ #category : 'announcements' }
OPController >> internalSubscribeTo: aModel [

aModel announcer
when: OPElementRenamed
do: [ self diagramElement modelChanged ]
for: self
aModel when: OPElementRenamed send: #modelChanged to: self
]

{ #category : 'announcements' }
OPController >> internalUnsubscribeFrom: aModel [
aModel announcer unsubscribe: self

aModel unsubscribe: self
]

{ #category : 'testing' }
Expand All @@ -168,7 +166,7 @@ OPController >> isHideable [
{ #category : 'testing' }
OPController >> isRendered [

^ self diagramElement isNotNil and: [ self diagramElement isRendered ]
^ self diagramElement isRendered
]

{ #category : 'testing' }
Expand Down Expand Up @@ -196,7 +194,7 @@ OPController >> model: aModel [
{ #category : 'announcements' }
OPController >> modelChanged [

self diagramElement ifNotNil: [ :de | de modelChanged ]
self diagramElement modelChanged
]

{ #category : 'accessing' }
Expand Down Expand Up @@ -245,18 +243,30 @@ OPController >> remove [
{ #category : 'destruction' }
OPController >> removeController [

self model ifNotNil: [ self removeDependentControllers ].
self diagramController ifNil: [ ^ self ].
self diagramController deselectAll.
self removeDiagramElement.
self diagramController removeController: self
self model ifNotNil: [ :m |
self
removeDependentControllers;
internalUnsubscribeFrom: m ].
self removeFromDiagramController.
self removeRender
]

{ #category : 'destruction' }
OPController >> removeControllerAndDiagramElement [

self model ifNotNil: [ :m |
self
removeDependentControllersAndDiagramElements;
internalUnsubscribeFrom: m ].
self removeFromDiagramController.
self removeDiagramElement
]

{ #category : 'destruction' }
OPController >> removeControllerAndModel [

self removeDependent.
self removeController.
self removeControllerAndDiagramElement.
self removeModel.
self model: nil
]
Expand All @@ -272,19 +282,27 @@ OPController >> removeDependent [

{ #category : 'destruction' }
OPController >> removeDependentControllers [

self dependentControllers do: [ :each |
self diagramController controllers
detect: [ :ctrl | ctrl model = each model ]
ifFound: #removeController ]
]

{ #category : 'destruction' }
OPController >> removeDependentControllersAndDiagramElements [
self dependentControllers
do: [ :each |
self diagramController controllers
detect: [ :ctrl | ctrl model = each model ]
ifFound: #removeController ]
ifFound: #removeControllerAndDiagramElement ]
]

{ #category : 'destruction' }
OPController >> removeDiagramElement [

self diagramElement ifNil: [ ^ self ].
diagramElement remove.
diagramElement := nil
self diagramElement remove.
self diagramElement: OPNoShape new
]

{ #category : 'destruction' }
Expand All @@ -298,6 +316,14 @@ OPController >> removeFigure [
self figure remove
]

{ #category : 'destruction' }
OPController >> removeFromDiagramController [

self diagramController ifNil: [ ^ self ].
self diagramController deselectAll.
self diagramController removeController: self
]

{ #category : 'destruction' }
OPController >> removeModel [

Expand All @@ -322,7 +348,7 @@ OPController >> removeRender [
{ #category : 'figures' }
OPController >> roassalShape [

^ self diagramElement ifNotNil: [ :found | found roassalShape ]
^ self diagramElement roassalShape
]

{ #category : 'canvas actions' }
Expand Down
20 changes: 14 additions & 6 deletions repository/OpenPonk-Core/OPDiagramController.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -464,15 +464,15 @@ OPDiagramController >> hasUndo [
OPDiagramController >> hideAllElements [

[ self controllers isNotEmpty ] whileTrue: [
self controllers anyOne removeController ].
self controllers anyOne removeControllerAndDiagramElement ].
self canvas signalUpdate
]

{ #category : 'figures' }
OPDiagramController >> hideModelFromDiagram: aModel [
self
controllerForModel: aModel
ifFound: [ :ctrl | ctrl removeController ]
ifFound: [ :ctrl | ctrl removeControllerAndDiagramElement ]
]

{ #category : 'protocol-canvas' }
Expand Down Expand Up @@ -615,13 +615,15 @@ OPDiagramController >> remove [

{ #category : 'destruction' }
OPDiagramController >> removeAllControllers [
[ self controllers isNotEmpty ]
whileTrue: [ self controllers anyOne removeController ]

[ self controllers isNotEmpty ] whileTrue: [
self controllers anyOne removeController ]
]

{ #category : 'controllers management' }
OPDiagramController >> removeController: aController [
self controllers remove: aController ifAbsent: [ ]
self controllers remove: aController ifAbsent: [ ].
self removeMouseEventsFor: aController roassalShape
]

{ #category : 'deprecated' }
Expand Down Expand Up @@ -674,6 +676,12 @@ OPDiagramController >> removeModelOfRoassalShape: aFigure [
(self controllerForRoassalShape: aFigure) removeControllerAndModel
]

{ #category : 'accessing' }
OPDiagramController >> removeMouseEventsFor: aFigure [

aFigure announcer unsubscribe: self
]

{ #category : 'accessing' }
OPDiagramController >> rendered: aController [

Expand Down Expand Up @@ -821,7 +829,7 @@ OPDiagramController >> updateAfterDiagramFocused [
self controllers do: [ :each |
(showableElements includes: each model)
ifTrue: [ each updateAfterDiagramFocused ]
ifFalse: [ each removeController ] ]
ifFalse: [ each removeControllerAndDiagramElement ] ]
]

{ #category : 'userinterface' }
Expand Down
16 changes: 13 additions & 3 deletions repository/OpenPonk-Core/OPDiagramOnlyShape.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Class {
#traits : 'OPTBorderColoredAsStroke - {#updateRenderFromStyles}',
#classTraits : 'OPTBorderColoredAsStroke classTrait',
#instVars : [
'uuid'
'uuid',
'announcer'
],
#category : 'OpenPonk-Core-CommonElements',
#package : 'OpenPonk-Core',
Expand Down Expand Up @@ -43,10 +44,10 @@ OPDiagramOnlyShape class >> stonAllInstVarNames [
{ #category : 'accessing' }
OPDiagramOnlyShape >> announcer [

^ roassalShape ifNotNil: #announcer
^ announcer ifNil: [ announcer := Announcer new ]
]

{ #category : 'accessing' }
{ #category : 'initialization' }
OPDiagramOnlyShape >> initialize [

super initialize.
Expand Down Expand Up @@ -83,3 +84,12 @@ OPDiagramOnlyShape >> uuid [

^ uuid
]

{ #category : 'announcement registration' }
OPDiagramOnlyShape >> when: anAnnouncementClass send: aSelector to: aReceiver [

^ self announcer
when: anAnnouncementClass
send: aSelector
to: aReceiver
]
9 changes: 9 additions & 0 deletions repository/OpenPonk-Core/OPDiagramOnlyShapeWithText.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Class {
#name : 'OPDiagramOnlyShapeWithText',
#superclass : 'OPDiagramOnlyShape',
#traits : 'OPTResizableFigureWithText',
#classTraits : 'OPTResizableFigureWithText classTrait',
#category : 'OpenPonk-Core-CommonElements',
#package : 'OpenPonk-Core',
#tag : 'CommonElements'
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ OPDirectionalRelationshipController >> registerModelIn: aParentModel [
{ #category : 'rendering' }
OPDirectionalRelationshipController >> renderSimplified [

diagramElement := self diagramElementClass renderSimplifiedForController: self.
self diagramElement:
(self diagramElementClass renderSimplifiedForController: self)
]

{ #category : 'construction' }
Expand Down
4 changes: 2 additions & 2 deletions repository/OpenPonk-Core/OPEdge.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ OPEdge >> innerWaypoints: aCollection [
OPEdge >> remove [

super remove.
self source: nil.
self target: nil
self source: OPNoShape new.
self target: OPNoShape new
]

{ #category : 'rendering' }
Expand Down
Loading

0 comments on commit 3dad350

Please sign in to comment.