Move object to last position in list

BlitzMax Forums/BlitzMax Programming/Move object to last position in list

nawi(Posted 2005) [#1]
I need to move object or a link to last position in a list.

Method New()
Link:Tlink = ListAddLast(CurrentGUI.WindowList,Self)
End Method


'place the link to last
RemoveLink(Win.Link)
Win.Link = ListAddLast(CurrentGUI.WindowList,Win)


It doesnt work and creates a memory leak.


nawi(Posted 2005) [#2]
I have tried many ways and RemoveLink doenst seem to remove the object, thus creating a mem leak.

But 'CurrentGUI.WindowList.Remove Win' does remove it, and If I add it to the list then I also get mem leak :/


Robert Cummings(Posted 2005) [#3]
ListRemove mylist,obj
ListAddLast mylist,obj

just removing it and adding it will put it on the end.


Cajun17(Posted 2005) [#4]
It's probably not a memory leak. It has to do with the way memory is handled in Max.

When you free an object the memory is flagged as available the next time you call flushmem(), but it isn't given back to the system. If you call remove() and then AddLast() without flushing the memory in between new memory will be allocated becaus the old memory is still considered occupied.

Look at http://www.blitzwiki.org/index.php/FlushMem


gman(Posted 2005) [#5]
an alternative, and this may not be what you need, is to override the compare method on the types you are storing. return -1 for less than, 0 for equal, and 1 for greater than. then all you need to do is change on the instance of the type whatever the compare is using to base its values on and then call the sort method of the TList instance.