When doing an "list.AddLast(obj)" that method returns an "TLink" object. You can use this "TLink" to directly access the item in the list and skip "searching" through the list until the desired object is found. so in essence:Type TMyType Field link:TLink...End TypemyType.link = list.AddLast(myType)'remove:myType.link.Remove()

SuperStrictType TBody Field X:Int Field Y:Int Field PopulationID:TLink Function Create:TBody() Local Body:TBody=New TBody 'Add the newly created Body to the Population list Body.PopulationID = Population.AddLast(Body) Return Body End Function Method Destroy() ' None of these seem to work: HOw to ensure removal of the object and memory cleanup? 'Population.Remove(PopulationID) 'ListRemoveLink(Population,PopulationID) 'Population.RemoveLink(PopulationID) 'PopulationID.Remove GCCollect End Method Method DrawCell() DrawRect((X*CELL_SIZE)+1,(Y*CELL_SIZE)+1,CELL_SIZE-2,CELL_SIZE-2) End MethodEnd Type Const POP_MAX:Int = 500 'Maximum Total PopulationGlobal Population:TList 'Iterable List of objects in PopulationGlobal GPU:TGraphics 'Graphics Mode ObjectConst CELL_SIZE:Int = 8Global CELL_X:IntGlobal CELL_Y:IntRuntimeFunction Runtime() Initialise Loop CloseDownEnd FunctionFunction Initialise() InitialiseGPU InitialisePopulationEnd FunctionFunction InitialiseGPU() SetGraphicsDriver(GLMax2DDriver(),GRAPHICS_BACKBUFFER) GPU:TGraphics=Graphics(DesktopWidth(),DesktopHeight(),DesktopDepth(),DesktopHertz()) CELL_X = GraphicsWidth()/CELL_SIZE CELL_Y = GraphicsHeight()/CELL_SIZE End FunctionFunction InitialisePopulation() Population = CreateList() Local Iter:Int For Iter= 1 To POP_MAX CreateRandomBody() NextEnd FunctionFunction Loop() While (Not(KeyHit(KEY_ESCAPE))) LoopUpdate WendEnd FunctionFunction LoopUpdate() UpdateDisplay CheckInputEnd FunctionFunction UpdateDisplay() DrawCells DrawDiagnostics FlipEnd FunctionFunction DrawDiagnostics() DrawText(GCMemAlloced(),0,0)End FunctionFunction DrawCells() Local Iter:TBody For Iter=EachIn Population Iter.DrawCell Next End FunctionFunction CheckInput() If (MouseHit(1)>0) FindAndRemoveBodyInCell(GetMouseCellX(),GetMouseCellY()) End IfEnd FunctionFunction GetMouseCellX:Int() Local X:Int=MouseX() Return X/CELL_SIZE End FunctionFunction GetMouseCellY:Int() Local Y:Int=MouseY() Return Y/CELL_SIZE End FunctionFunction UnInitialiseGPU() EndGraphics()End FunctionFunction UnInitialise() UnInitialiseGPUEnd FunctionFunction CloseDown() UnInitialise GCCollect EndEnd FunctionFunction CreateRandomBody:TBody() Local X:Int=Rand(0,CELL_X-1) Local Y:Int=Rand(0,CELL_Y-1) While(GetIsAlreadyHere(X,Y)) ' I know this is horrendous, but it's just a easy insurance and not relevant to the actual problem investigated X=Rand(0,CELL_X-1) Y=Rand(0,CELL_Y)-1 Wend Local Body:TBody=TBody.Create() Body.X=X Body.Y=Y Return BodyEnd FunctionFunction GetIsAlreadyHere:Int(X:Int,Y:Int) Local Iter:TBody For Iter=EachIn Population If Iter.X=X And Iter.Y=Y Then Return True Next Return FalseEnd FunctionFunction FindAndRemoveBodyInCell:TBody(X:Int,Y:Int) Local Iter:TBody Local Found:TBody For Iter=EachIn Population If (Iter.X=X And Iter.Y=Y) Found=Iter Exit End If Next If (Found<>Null) Found.Destroy End IfEnd Function

SuperStrictType TBody Field X:Int Field Y:Int Field PopulationID:TLink Function Create:TBody() Local Body:TBody=New TBody 'Add the newly created Body to the Population list Body.PopulationID = Population.AddLast(Body) Return Body End Function Method Destroy() ListRemoveLink(Population,PopulationID) PopulationID=Null End Method Method DrawCell() DrawRect((X*CELL_SIZE)+1,(Y*CELL_SIZE)+1,CELL_SIZE-2,CELL_SIZE-2) End MethodEnd Type Const POP_MAX:Int = 500 'Maximum Total PopulationGlobal Population:TList 'Iterable List of objects in PopulationGlobal GPU:TGraphics 'Graphics Mode ObjectConst CELL_SIZE:Int = 8Global CELL_X:IntGlobal CELL_Y:IntRuntimeFunction Runtime() Initialise Loop CloseDownEnd FunctionFunction Initialise() InitialiseGPU InitialisePopulationEnd FunctionFunction InitialiseGPU() SetGraphicsDriver(GLMax2DDriver(),GRAPHICS_BACKBUFFER) GPU:TGraphics=Graphics(DesktopWidth(),DesktopHeight(),DesktopDepth(),DesktopHertz()) CELL_X = GraphicsWidth()/CELL_SIZE CELL_Y = GraphicsHeight()/CELL_SIZE End FunctionFunction InitialisePopulation() Population = CreateList() Local Iter:Int For Iter= 1 To POP_MAX CreateRandomBody() NextEnd FunctionFunction Loop() While (Not(KeyHit(KEY_ESCAPE))) LoopUpdate WendEnd FunctionFunction LoopUpdate() CheckInput UpdateDisplayEnd FunctionFunction UpdateDisplay() Cls DrawCells DrawDiagnostics FlipEnd FunctionFunction DrawDiagnostics() DrawText(GCMemAlloced(),0,0)End FunctionFunction DrawCells() Local Iter:TBody For Iter=EachIn Population Iter.DrawCell Next End FunctionFunction CheckInput() If (MouseHit(1)>0) FindAndRemoveBodyInCell(GetMouseCellX(),GetMouseCellY()) End IfEnd FunctionFunction GetMouseCellX:Int() Local X:Int=MouseX() Return X/CELL_SIZE End FunctionFunction GetMouseCellY:Int() Local Y:Int=MouseY() Return Y/CELL_SIZE End FunctionFunction UnInitialiseGPU() EndGraphics()End FunctionFunction UnInitialise() UnInitialiseGPUEnd FunctionFunction CloseDown() UnInitialise GCCollect EndEnd FunctionFunction CreateRandomBody:TBody() Local X:Int=Rand(0,CELL_X-1) Local Y:Int=Rand(0,CELL_Y-1) While(GetIsAlreadyHere(X,Y)) ' I know this is horrendous, but it's just a easy insurance and not relevant to the actual problem investigated X=Rand(0,CELL_X-1) Y=Rand(0,CELL_Y)-1 Wend Local Body:TBody=TBody.Create() Body.X=X Body.Y=Y Return BodyEnd FunctionFunction GetIsAlreadyHere:Int(X:Int,Y:Int) Local Iter:TBody For Iter=EachIn Population If Iter.X=X And Iter.Y=Y Then Return True Next Return FalseEnd FunctionFunction FindAndRemoveBodyInCell:TBody(X:Int,Y:Int) Local Iter:TBody Local Found:TBody For Iter=EachIn Population If (Iter.X=X And Iter.Y=Y) Found=Iter Iter=Null Exit End If Next If (Found<>Null) Found.Destroy found=Null End If GCCollectEnd Function