Hi,
I seem to eat texture memory when I try to determine the number of pixels text would occupy, via the code below. Note that I remove the text object immediately.
I call:
ss_get_text_width (“hi there”, 20)
and
system.getInfo (“textureMemoryUsed”)
before and after, and see that the delta is about 13 KB (on Android) or 5 KB (on simulator).
The loss seems 100% reliable. I tried doing the call 100 times, and lost the same amount each time.
And, calls to “collectgarbage ()” have no effect on this
(I.e., the texture memory use does not go down after a garbage collection.)
What am I overlooking?
I’m overly paranoid here, because I don’t (*currently*) don’t intend to call this routine more than a few dozen times at startup (while dynamically sizing some UI items on my screen), but … I don’t like losing memory
Is there a better way to dynamically determine how much room a newText object will take on the screen?
thanks,
Stan
----------------------------------------------------------------- function ss\_get\_text\_width (s, fsize) -- returns # pixels text would occupy (width, height) local t\_dummy local height = 0 local width = 0 if fsize then t\_dummy = display.newText ({text = s, x = 1, y = 1, fsize = fsize} ) else t\_dummy = display.newText ({text = s, x = 1, y = 1} ) end if t\_dummy then width, height = t\_dummy.width, t\_dummy.height --display.remove (t\_dummy) t\_dummy:removeSelf () t\_dummy = nil end return width, height end -- ss\_get\_text\_width proc