Reflections possible memory leak

Archives Forums/BlitzMax Bug Reports/Reflections possible memory leak

Kernle 32DLL(Posted 2009) [#1]
I'm not 100% sure, but is there any reason the method TTypeId.ForObject(Null) should increase the memory used (GCMemAlloced()) by around 30000 Bytes? No? Tought so.

It gets even stranger by the fact, that this memory increase is only done once, so it does only happen once during runtime.

Finally, some code (Note that you can simply use TTypeId.ForObject(Null), too, it doesnt matter)

Type TBlubb
   Field Gaga:Byte
End Type

Local Blubb:TBlubb = New TBlubb

GCCollect()
Print GCMemAlloced()

TTypeId.ForObject(Blubb)

GCCollect()
Print GCMemAlloced()


So long,
Kernle


Htbaa(Posted 2009) [#2]
I haven't looked into the source of the reflection module but perhaps it's possible that some static field is being filled with data that increases the memory usage, which doesn't get freed afterwards. Which is understandable if it's a static field (Global).


Brucey(Posted 2009) [#3]
Finally, some code

This is not a good example.

For a proper test you need have it run over a period of time, to allow the memory allocator to balance out.

You will tend to see the memory increase for a while before it levels off. (If it always increased, no matter what, then yes, I would have to agree that there was a leak).

SuperStrict

Type TBlubb
   Field Gaga:Byte
End Type

Const total:Int = 10000
Local count:Int = 0

For Local i:Int = 0 Until 1000000
	Local Blubb:TBlubb = New TBlubb

	TTypeId.ForObject(Blubb)

	count:+ 1
	
	If count = total Then
		count = 0
		
		Print GCMemAlloced()
	End If

	GCCollect()

Next

GCCollect()
Print GCMemAlloced()



Tommo(Posted 2009) [#4]
Type reflection infomation is generated by demand, it will be kept after that.


Kernle 32DLL(Posted 2009) [#5]
What kind of reflection data is that supposed to be? And why does it need to be kept in memory?


plash(Posted 2009) [#6]
And why does it need to be kept in memory?
So it's faster when you use reflection for stuff later.