diff --git a/src/Molecule-Tests/MolComponentManagerTest.class.st b/src/Molecule-Tests/MolComponentManagerTest.class.st index b45e534..8877b21 100644 --- a/src/Molecule-Tests/MolComponentManagerTest.class.st +++ b/src/Molecule-Tests/MolComponentManagerTest.class.st @@ -9,13 +9,19 @@ Class { { #category : #'setUp - tearDown' } MolComponentManagerTest >> setUp [ + super setUp. - MolComponentManager cleanUp + MolComponentManager cleanUp. + Smalltalk garbageCollect. + Smalltalk garbageCollectMost. ] { #category : #'setUp - tearDown' } MolComponentManagerTest >> tearDown [ + MolComponentManager cleanUp. + Smalltalk garbageCollect. + Smalltalk garbageCollectMost. super tearDown ] @@ -110,40 +116,22 @@ MolComponentManagerTest >> testDeploymentServices [ { #category : #tests } MolComponentManagerTest >> testFlushComponents [ + | nb | - - "Create some classics components to flush" - 1 to: 10 do:[ :i | MolCompleteComponentImpl new ]. + "Create some classic components to flush" + 1 to: 10 do: [ :i | MolCompleteComponentImpl new ]. "Create some augmented class as components to flush" - 1 to: 10 do:[ :i | MolAugmentedClassToAComponent new ]. - "Check created instances" - self assert: MolCompleteComponentImpl allInstances size equals: 10. - self assert: MolAugmentedClassToAComponent allInstances size equals: 10. + 1 to: 10 do: [ :i | MolAugmentedClassToAComponent new ]. - nb := MolComponentManager flushComponents. - self assert: nb equals: 20. - self assert: MolCompleteComponentImpl allInstances size equals: 0. - self assert: MolAugmentedClassToAComponent allInstances size equals: 0. -] - -{ #category : #'setUp - tearDown' } -MolComponentManagerTest >> testGarbageCollect [ - - "Create some classics components to clean" - - 1 to: 10 do: [ :i | - MolCompleteComponentImpl start: ('test' , i printString) asSymbol ]. - "Check created instances" self assert: MolCompleteComponentImpl allInstances size equals: 10. + self + assert: MolAugmentedClassToAComponent allInstances size + equals: 10. + nb := MolComponentManager flushComponents. - 1 to: 10 do: [ :i | - MolCompleteComponentImpl stop: ('test' , i printString) asSymbol ]. - - Smalltalk garbageCollect. - - self assert: MolCompleteComponentImpl allInstances size equals: 0 + self assert: nb equals: 20 ] { #category : #tests } diff --git a/src/Molecule/MolComponentManager.class.st b/src/Molecule/MolComponentManager.class.st index 2eba83e..2302f71 100644 --- a/src/Molecule/MolComponentManager.class.st +++ b/src/Molecule/MolComponentManager.class.st @@ -59,36 +59,45 @@ MolComponentManager class >> cleanUp: aBoolean [ { #category : #cleanup } MolComponentManager class >> deepCleanUp [ + | i j | - "Try to remove non garbaged component instances" Smalltalk garbageCollect. - + Smalltalk garbageCollectMost. + self cleanUp. MolUtils log: 'Starting a deep cleanUp.'. - MolComponentFactory allInstancesDo: [ :factory | (factory == MolComponentFactory default) ifFalse:[factory release]]. + MolComponentFactory allInstancesDo: [ :factory | + factory == MolComponentFactory default ifFalse: [ factory release ] ]. i := self flushComponents. j := i. - + "Try to reflush" - i > 0 ifTrue:[ + i > 0 ifTrue: [ + + Smalltalk garbageCollect. + Smalltalk garbageCollectMost. + (Delay forMilliseconds: 500) wait. - j := self flushComponents. - ]. - - MolUtils log: 'Deep Cleanup: ',i printString,' lost component(s) found and released.'. - i <= 0 ifFalse:[ - j <= 0 ifFalse:[ - MolUtils showInformation: 'Warning : Cannot release ',i printString,' component(s) after two clean pass, please try again to confirm correct cleanup.'. - ] ifTrue:[ - MolUtils showInformation: 'Clean success : ',i printString,' lost component(s) found and released.'. - ]. - ] ifTrue:[ - MolUtils showInformation: 'No problem : image was clean.'. - ]. - - MolUtils log: 'End of the deep cleanUp.'. + j := self flushComponents ]. + + MolUtils log: 'Deep Cleanup: ' , i printString + , ' lost component(s) found and released.'. + i <= 0 + ifFalse: [ + j <= 0 + ifFalse: [ + MolUtils showInformation: + 'Warning : Cannot release ' , i printString + , + ' component(s) after two clean pass, please try again to confirm correct cleanup.' ] + ifTrue: [ + MolUtils showInformation: 'Clean success : ' , i printString + , ' lost component(s) found and released.' ] ] + ifTrue: [ MolUtils showInformation: 'No problem : image was clean.' ]. + + MolUtils log: 'End of the deep cleanUp.' ] { #category : #singleton } @@ -104,23 +113,25 @@ MolComponentManager class >> default [ { #category : #'initialize-release' } MolComponentManager class >> flushComponents [ - "Flush all components : detect all component class instances of the Pharo image and disconnect each componentconnector, return number of flushed components" + "Flush all components : detect all component class instances of the Pharo image and disconnect each component connector, return number of flushed components" + | i | i := 0. "First : search direct component class subinstances (inheritance from MolAbstractComponentImpl class)" - MolAbstractComponentImpl allSubInstancesDo:[ :component | - component componentConnector: nil. i := i + 1. - ]. - "Second : search augmented class as a component instances (using the MolComponentImpl trait)" - MolComponentImpl users do: [ :impl | - impl allInstances do: [:component | component componentConnector: nil. i := i + 1]. - ]. - + MolAbstractComponentImpl allSubInstancesDo: [ :component | + component componentConnector: nil. + i := i + 1 ]. + "Second : search augmented class component instances (using the MolComponentImpl trait)" + MolComponentImpl users do: [ :impl | + impl allInstances do: [ :component | + component componentConnector: nil. + i := i + 1 ] ]. + SmalltalkImage cleanUp. Smalltalk garbageCollect. Smalltalk garbageCollectMost. - - ^i + + ^ i ] { #category : #'initialize-release' }