Clear cache remote image
I need help. How I can clean the cache of a remote image of a imageview?
Example: KitchenSink> BaseUI> Views> Image Views> Remote Image
First download the image and show. The following, show the image of the cache.
I need to clean the memory/cache when close the current window, because I have a list of 2,000 photos (with scrollview).
Thanks
19 Answers
-
seems silly now to answer this, but i came across it just now so maybe someone can use this answer. I did the old flash trick of placing a cashe buster on the call to the image string. something like image.jpg?cashebuster=01902923 which i set up as the time
var casheBuster = new Date(); var view[i] = Titanium.UI.createImageView({ image:'image/'+image+'.jpg?casheBuster='+casheBuster.getTime() });
-
Thank you very much. I appreciate the help.
I thought it was my problem, I have been all weekend trying out different methods and could not.
And with the solution you propose will solve the problem of ScrollView (limit of pages), but not address the problem of freeing memory remote images.
In the video I have shown (http://www.vimeo.com/13438794) can view the memory available when I access windows remote images, and closes not free.
The test is simple:
1 .- Look at the memory available:
Titanium.API.info ('Available memory:' + Titanium.Platform.availableMemory)
2 .- Creates and opens a window
3 .- Insert a ImageView with an external URL:
var imageView = Titanium.UI.createImageView ((url: 'http://afosorio.files.wordpress.com/2009/01/space-desktop.png')); view.add(imageView);
4 .- Look at the memory available
5 .- Close the window
6 .- Look at the memory available. Not released.
7 .- open the window with the previous image.
8 .- You will see that no discharge, the sample directly, it remains in cache
Yet "erasing" the image:
imageView.image = null;
and / or delete the object …
view.remove (imageView)
Not released …
I would use a manual system for displaying images, but if I can not free the memory using remote images, I can not work with Titanium, because I have a gallery with 65 albums of photographs and 2000 images in total.
Do you know when v.4.1 will be available? or is it advisable to work this application (photo gallery) in Obj-C? :(
-
Made an improvement with image gallery, no crashes so far.
Here's what i discovered.
On open gallery window, do not use modal or animate, just plain open window, otherwise it would stuck on blank screen when closing, that's after accessing multiple galleries and the app gets heavy.
Since scrollable crash on large gallery, I use touchstart and touchend eventlistener to detect swipe direction, then change image accordingly. Do not use swipe listener as that event trigger multiple times, buggy!
For instance,x is the right or left direction position. z is your image index, 20 is the set point, first to end touch position (swipe amount) to trigger the swipe. Lower number is more sensitive.
var x=0; var z=0; imgobj.addEventListener('touchstart',function(e){ x = e.x; }); imgobj.addEventListener('touchend',function(e){ x=x - e.x; if(x<-20){ if(z!=0){ z=z-1; bigimg.image=imglist[z]; } } else if(x>20 && z<total-1){ z=z+1; bigimg.image=imglist[z]; } });
If you need an indicator, add a spinner on the window before image.
On closing window, use "remove" imageview object. I saw it released the memory if i were to open a different gallery after the first. Reopening the same gallery, however, is not.
Now i am working on thumbnails option in additional to the scrollable images, hope it sticks.
Good Luck and finger cross.
-
Raul,
I have articles with image galleries and have tried every possible ways i could think of, from scrollable images, to only load and append image in the view when user scroll next but it's still crash after accessing couple or more galleries. It crashs when closing or crash in between image viewing.
I also tried webview, and created a scrolling view with touch events to change images imitating scrollable object but nothing is working. I already ran out of ideas how to tackle the problem. Some of it only load 20, 30 plus and nothing over 80. I don't think the imageview free memory after closing, that's the only problem i could think of.
Unless Ti solve this on the upcoming 1.4 final, photo galley is less likely to ran without crashing, sadly.
-
Same Problem here. Tried different ways… Close the window, remove the children, overwrite the children, remove the scroll view etc.
I use also a scroll view with around 100 remote images. When I change the view five times the app crashs. Thats because out of memory would I say.
There must be a way to clean up the memory!Any ideas would be very helpful!
-
The disturbing point on this situation is, that the iPad/iPhone Simulator form the Apple SDK never run out of memory…
@Raul Magdaleno … did you try something like -> RaulsScrollView.close() ?
-
But the problem is not the ScrollView, the problem is that it does not clean the memory of remote images. In the example I have no use ScrollView.
The problem of ScrollView is another (crash with multiple views), like his friend Daniel Lim says that we can have an alternative.
I will just continue with the application (Blog, Forum, Resources ,…) and when finished, if not out version 4.1, see a solution (create the gallery from X-Code).
-
I did a test download all images, and then read from local them with ImageView. Continues to consume too much memory, and not released on exit. It is therefore not a problem of remote images. ImageView and WebView is a problem.
I have been tested with v. 1.3.2 and 1.3.3.
I surrender :/
-
What size are the images? The iOs SDK recommend not to use images bigger than 1024x1024
-
I quickly made an application (a bit ugly) so we can all try. As you see, by uploading images and close the window, still consuming memory. Please try it.
app.js: http://pastie.org/1054044
fotos.js: http://pastie.org/1054045
The title shows the memory used in each window (fotos.js and app.js)
1) Click on Test It
2) Displays 5 photos. The window uses 11mb of memory.
3) Close the window. You will see that the application has been used 19mb.
4) Click on Test It. will see that the first five photos do not consume memory until they reach the sixth (because they are cached) and continues to consume memory. View more pictures.
5) Close the window. You'll see that still consumes memory even closing the window.
6) … infinite loop…. 1.455.344.344 GB :D
I hope your comments. :?
-
nobody has been able to test it?
-
Did anyone find a solution to this? I'm running into the same issue with a video player.
-
I'm having the same problem with iOS 4.2 and Titanium 1.6.0.
Did somebody find a way to free memory for ImageView ?Thanks
-
bummer this is still happening 4 months later… is there maybe a way to just reuse the same imageview over and over again instead of creating new imageview for each image?
-
I still issue this kind of problems. Anyone have a solution?
-
I havent run into memory issues, but here is a link to a post by a person that has a unique method for clearing memory built up from windows, http://developer.appcelerator.com/question/116867/this-is-a-solution-to-your-memory-woes
-
Thanks for responding.
The problem is when loading a remote image, closing the window does not clear the memory. When you load 200 images (in different windows) consumes 50mb of memory even if you close the window. Therefore, in the iPhone the application exits.
I have tried cleaning …
imageView.image = null;
win.remove (imageView)
…I tried to use a WebView, instead of ImageView, and although it works "better", not the memory clean, therefore it is the same.
I do not know what to try. It is a photographers gallery application, so the most interesting part is the photo gallery.
No one is wrong?
VIDEO: http://www.vimeo.com/13438794
Thanks
-
Did anyone try saving the images locally and then using them instead of opening from remote?
-
Try to add a random string to the end of the image on each window open.
Something like:
var rand = Math.random();
then when you build the image
image:"url_to_the_image.png?"+rand