Re: Problem with CreateImage
I´m developing a J2ME client program as part of a large project in which I need to create a lot (hundreds) of images. When I run it on
an emulator or a Samsung phone everything goes fine. But, when I use a Nokia I end up running out of memory, because something is not
being freed; and it is actually freed on Samsungs and the emulator. This can be easily observed using Symbian´s MemoryMonitor; or the
advanced MemoryMonitor available in [url]http://www.mikeullrich.com/[/url]
I have seen that the "createImage" method uses native memory from symbian, which should actually be freed. I don´t know wether this
problem is of Symbian or Nokia´s KVM implementation.
Does anyone know of any similar problem(s) with nokia phones and memory not being liberated? Anyone can shed some light on this?
Thanks in advance.
.
Re: Problem with CreateImage
Which Nokia phones have you tried it on?
There are some memory leaks in reading files on some Nokia series 60 devices, which means you need to cache the data rather than reloading it.
>as part of a large project in which I need to create a lot (hundreds)
That sounds like a bad idea. I'm sure a lot of phones would be happier if you had much fewer images by packing the images together and then just set the clip region to draw a part of that image.
Re: Problem with CreateImage
Hola, ya he encontrado la solución al problema. Nokia no tiene perdidas de memoria al crear imagenes. El problema es el siguiente, si creas imánes, tienes que estar 100% seguro de que el objeto que apunta a esa imagen se libera. En muchos télefonos estos objetos si se liberan, pero en los Nokia, tienes que asegurarte de poner las referencias a null explicitamente. En nuestra aplicación teniamos muchas referencias cruzadas. Pues para conseguir que finalmente se liberase todos los recursos hemos tenido que ir limpiando las referencias una por una. Se puede probar que efectivamente Nokia no pierde memoria al crear imagenes si estas se desreferencia correctamente mediante un Midlet de prueba y el Memory Monitor. Todo el problema biene de cuando no se libera la referencia en Java hacia el objeto de memoria, entonces symbian conserva de forma nativa la representanción en memoria de la imagen (que ocupa mucho mas que la representación del objeto en Java, por eso decrece mucho mas rápido la memoria libre que le va quedando al teléfono que el heap de la aplicación). Todo esto surge debido a que la KVM es mucho menos inteligente con respecto a liberación de recursos que KVM de Samsung o del emulador.
Como conclusión decir que NOKIA no tiene un bug de memoria, sino que el recolector de basura de la KVM es mucho menos inteligente que otros. Por lo que aseguraros de que todas las posibles referencias a las imagenes son null, y no queda ninguna referencia colgada por ningún lado, ni directa ni indirectamente.
Re: Problem with CreateImage
Hello,
I have just found the solution for this problem. Nokia has no memory leaks when creating images. The problem is: if you create images, then
you have to be fully sure that the object pointing to that image will be liberated. In most phones these objects are actually liberated, but
in Nokia you have to make sure you explicitly point every reference to NULL. In our app. we had a lot of cross references and, in order to get
every resource liberated, we have needed to clean references one by one. You can then confirm that no memory leaks exist on Nokia when creating
images if you dereference them as explained before. All of the problem comes when you do not dereference the java references to the object:
symbian keeps the image´s memory representation natively, and this takes up much more space than java´s object representation; that´s why the
phone´s free memory decreases much faster than the heap. All this is due to Nokia´s KVM being much less "intelligent" regarding to resource
freeing than it is on Samsung phones or an Emulator.
In brief: Nokia has no memory bugs, but a much less intellingent KVM garbage collector than others. So, make sure you point to null every
unused reference, and you don´t leave any "hung up" reference, either directly or indirectly.