StringBuilder question

AlDim

Member
Licensed User
Longtime User
Hi everyone :)

What is the best way to clear a StringBuilder variable?

I use initialize but i think that it isn't the best way, cause might make bigger the used memory.

If it was a string i would use a simple
B4X:
s = ""
but i don't know if its the same for a stringbuilder variable.

Sorry for my english in advance.
 

AlDim

Member
Licensed User
Longtime User
I am asking cause in my project Fantasy Name Generator i try too keep low memory use, so i clear/reuse list, variables, but i noticed that memory used is growing (very small amount :)) each time i generate names. Maybe is an android thing, don't know, that is the reason i am asking about StringBuilder object cause i don't know it. Can initialize of a StringBuilder use more memory? The active objects i am using are List, StringBuilder and ListView.
Maybe the checking program i use read wrong (official task manager of my Galaxy S Plus phone 2.3.3)

It isn't a big deal cause my app use small base memory and the grow is small, but if i can prevent it, why not do it :)

Sorry for my english in advance.

Link of the application
================
Fantasy Name Generator
 
Upvote 0

JesseW

Active Member
Licensed User
Longtime User
in android, when an object has no more references referencing it, it is destroyed and removed from memory. when a string builder, like any other b4a object, is initialized, the variable name releases any previous reference so it can reference the newly created object. the de-referenced object will be cleaned up and destroyed by android. thus, reinitializing a string builder creates no memory problems.
 
Upvote 0

AlDim

Member
Licensed User
Longtime User
Thank you for the information. Then i don't have to fear a memory error :)
If i understand correctly android will clear the de-referenced object. But it will choose the time, it doesn't have to be immediatly, correct?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
The thing to stress is that it will be dealt with when Android decides it should. If you are only using small amounts of memory, it may not be processed while you are watching it.

-------------------
Sent via Tapatalk
 
Upvote 0

AlDim

Member
Licensed User
Longtime User
Thank you all for your help.

Have a nice day and good programming :sign0008:
 
Upvote 0
Top