freeing images
BlitzMax Forums/BlitzMax Programming/freeing images
| ||
Try this code (obviously replace the image path with a valid one):Strict GCCollect() Print GCMemAlloced() Local pic:TImage = LoadImage("C:\BlitzMax\Jake\HolidayBonus\Data\Graphics\title.jpg") GCCollect() Print GCMemAlloced() pic = Null GCCollect() Print GCMemAlloced() I get this output: 17662 18370 18198 I have two questions: 1) Why doesn't it revert back to the original figure when pic = null is used. 2) When the picture is loaded in how come the memory allocation doesn't go up hugely, like by around 2Mb (for 800x600x32bit). I guess the mem allocated is just showing memory for variables etc not actual media used. In fact to prove point 2 I used Task Manager to show the mem used before and after the image was loaded and freed. I used this code: Strict Graphics 800,600,0 GCCollect() Print GCMemAlloced() While Not KeyHit(key_escape) Cls DrawText("Fresh",0,0) Flip Wend Local pic:TImage = LoadImage("C:\BlitzMax\Jake\HolidayBonus\Data\Graphics\title.jpg") GCCollect() Print GCMemAlloced() While Not KeyHit(key_escape) Cls DrawText("Loaded",0,0) Flip Wend pic = Null GCCollect() Print GCMemAlloced() While Not KeyHit(key_escape) Cls DrawText("Freed",0,0) Flip Wend Basically run that and run task manager. With no image loaded it takes up about 5.5MB. Then press escape, and it'll load the image (goes up to abou 7.5Mb), the press escape again and it drops down to 5.5Mb again. GOOD. But is there no way to show this "True" amount of memory allocated within BMax rather than having to use Task Manager, it would be great for debugging. Perhaps it's a simple API call... Also totally weirdly, in the full screen version, the memory use within BMax goes UP now down, look: 38526 40230 41334 Explain that! |
| ||
Hi, maybe you're running in debug mode. in NO DEBUG mode for your first code I got: 14058 14058' its because you're calling cgcollect and the image is gone. 14058 if I change it... Local pic:TImage = LoadImage("C:\top_main.jpg") GCCollect() for it... Local pic:TImage = LoadImage("C:\top_main.jpg") ' GCCollect() i get: 14058 14400 14058 |
| ||
Aha that's it debug mode, thanks. Anyway the other thing is how can we report the windows memory used (like task manager) in Blitz? |
| ||
Although you should know the answer from a different thread: Local is not inserted to the GC unless it is transfered to some "remaining" reference (list, global etc) as the GC knows up front that the variable will be dead straight away. This means: Local on application level never will enter the GC handling system. Local on scopes just die at the end of the scope |
| ||
Anyway the other thing is how can we report the windows memory used (like task manager) in Blitz? since BlitzMax 1.12: + (BRL.Blitz) MemUsage() gone. instead memusage use windows task manager |
| ||
Dreamora: OK, thanks for the local scope info. BlackSp1der: Bummer, no MemUsage command. |