Difference between GCMemAlloced and Task Manager
BlitzMax Forums/BlitzMax Programming/Difference between GCMemAlloced and Task Manager
| ||
| Hi guys, According to Windows Task Manager my Game has huge Memory Leak. The problem is That GCMemAlloced() function shows different results from Task Manager , and according to GCMemAlloced() there is no memory leak at all. GCMemAlloced() returns between 11831280 - 14611024 And Task Manager shows 430,844 K I wrote simple Type for Memory Usage Debuging to handle the problem
SuperStrict
Type GFDebugObject
Field idx:Int
Field name:String
Field cnt:Int
Field rm:Int
EndType
Type GFDebug
Global creted:Int
Global destroyed:Int
Global index:Int
Global list:TList = New TList
Global lastTime:Int
Global mem:Int
Method Add:Int(n:String)
index:+1
creted:+1
Local in:Short = False
For Local o:GFDebugObject = EachIn list
If n = o.name
in = True
o.cnt:+1
Exit
End If
Next
If Not in
Local o:GFDebugObject = New GFDebugObject
o.idx = index
o.name = n
o.cnt = 1
list.AddLast(o)
End If
End Method
Method Remove(n:String)
destroyed:+1
For Local o:GFDebugObject = EachIn list
If o.name = n
o.rm:+1
End If
Next
End Method
Method Draw()
Local y:Int = 20
SetColor 0, 0, 0
SetAlpha 0.6
DrawRect(480, 0, 500, list.Count() * 15 + 50)
SetColor 255, 0, 0
SetAlpha 1
Local t1:Int = MilliSecs()
If t1 > lastTime + 1000
lastTime = t1
mem = GCMemAlloced()
Print mem
End If
DrawText("Total Memory Usage : " + mem + " Total Created " + GFD.creted + " Total Deleted " + GFD.destroyed + " Live = " + (GFD.creted - GFD.destroyed), 500, y)
SetColor 255, 255, 0
For Local o:GFDebugObject = EachIn list
y:+15
DrawText("Class >> " + o.name + " Created = " + o.cnt + " Destroyed = " + o.rm + " Live Objects = " + (o.cnt - o.rm), 500, y)
Next
End Method
EndType
Usage Example
Global GFD:GFDebug = New GFDebug
Type MyType
Field a:Int
Method New()
If GFD GFD.Add("MyType")
EndMethod
Method Delete()
If GFD GFD.Remove("MyType")
EndMethod
EndType
In every Type I add those and everything works great. There is no MemLeak at all Any idea what is going on here? Thanks Last edited 2012 |
| ||
| The RAM shown on task manager is the RAM that windows windows is assigning to your program, not the RAM your program is using. Windows does a balance between the mem a program is using, the amount of RAM it is requesting and at wich ratio, and the available system RAM, in order to speed things up, and prevent mem fragmentation, so it pre-asignates more RAM if available, in order to make memalloc operations faster, and avoid memory swaps. All in all, the memory usage displayed on the task manager is not a reliable information unless you see it growin and growing without end to absurd values. then there's a mem leak. |
| ||
| Hi Ziggy, Thanks for your post . Yes it growing in Task Manager to 800,000 - 900,000 but in same time not growing according to GCMemAlloced() . I'm confused :) Edit: I am using Threaded Build Last edited 2012 |
| ||
| Yes, but it ends at some point or it does get your whole system mem? If it's not causing performance issues, don't bother it's usualy windows assigning more ram that required to ensure smoth performance |
| ||
| HeHe I have to try on some other machine I have 8.0 GB ,I am not sure . |
| ||
| By the way, unles you're actually using multithreading on your source code, using a thread build will make your application use more ram and run a bit slower |
| ||
| Thanks again, My game is Hidden Object game , open world , where you can walk from scene to scene ,which means every new screen is new level. I use multithreading just for level loading system ,to switch between levels faster and smoother. |