B4J Question Please help me understand memory used by classes

Patrick Clark

Active Member
Licensed User
I may be being stupid here but I am having a bit of trouble getting my head around the memory used by class instances.

If I have a Class called testClass which has in it a number of declared items, maybe a few Strings and so Maps and also some code.

When I use testClass.Initialize I assume some memory is used. If I do this 1000 times more and more memory is used.

How does that memory get released, I cannot see a way of closing an instance of a Class.
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
short anwer is you cant. if any of those strings and maps inside the class arent connected to any other part of the app, eventually they will be cleaned by the garbage collector. and by eventually i mean, it could simply not happen if the garbage collector doesnt want to, may be there is too much free ram.

if you are running into issues of memory, then it means that all those 1000 classes have connections that are preventing from being cleaned. that connection is called memory leak.
 
Upvote 0
Top