Memory usage
BlitzMax Forums/BlitzMax Programming/Memory usage
| ||
The following causes a constant increase in the amount of memory used. Why? ta! ' memory test Strict Graphics 640,480,0 Type test Field life Method die() life = life - 1 If life = 0 Then test_list.remove(Self) End Method End Type Global test_list:TList = CreateList() While Not KeyDown(key_escape) create_Test() kill_test() If KeyHit(key_1) Then Print MemAlloced() Flip Cls Wend End ' ### Create a test object Function Create_test() Local NewTest:Test NewTest = New Test NewTest.life = 1 test_List.AddLast( Newtest ) End Function ' ### Run the process that kills the test Function kill_test() For Local ThisTest:test = EachIn test_list ThisTest.die() Next End Function |
| ||
Question about your code The Newtest exists outside create_test because it is in the list right? So how can you remove it from the list when within one of its own methods? Cos then it shouldnt exist, but you are "in" it, so it needs to exist. no? |
| ||
ok thats a fair enough point, but the following still does the same...' memory test Strict Graphics 640,480,0 Type test Field life End Type Global test_list:TList = CreateList() While Not KeyDown(key_escape) create_Test() kill_test() If KeyHit(key_1) Then Print MemAlloced() Flip Cls Wend End ' ### Create a test object Function Create_test() Local NewTest:Test NewTest = New Test NewTest.life = 1 test_List.AddLast( Newtest ) End Function ' ### Run the process that kills the test Function kill_test() For Local ThisTest:test = EachIn test_list ThisTest.life = ThisTest.life-1 If Thistest.life = 0 Then test_list.remove(ThisTest) Next End Function |
| ||
You're using memalloced so, I assume, a backlevel of Bmax so will need to use a flushmem() statement. You should really install 1.18, upgrade to 1.20 and syncmods. I ran a similar test at 1.20 and the memory usage settles down... ' memory test Strict Graphics 640,480,0 Type test Field life Method die() life = life - 1 If life = 0 Then test_list.remove(Self) End Method End Type Global test_list:TList = CreateList() Local high_mem:Int=0 While Not KeyDown(key_escape) create_Test() DrawText CountList(test_list),0,10 kill_test() Local latest_mem:Int = GCMemAlloced() If latest_mem > high_mem high_mem = latest_mem DrawText high_mem , 0 , 0 DrawText CountList(test_list),40,10 Flip Cls Wend End ' ### Create a test object Function Create_test() Local NewTest:Test NewTest = New Test NewTest.life = 1 test_List.AddLast( Newtest ) End Function ' ### Run the process that kills the test Function kill_test() For Local ThisTest:test = EachIn test_list ThisTest.die() Next End Function |
| ||
ahh perfik, thank you, yup flushmem sorted it out good and proper :) i better upgrade too ;) |