Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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).


— asked July 18th 2010 by Raul Magdaleno
  • image
  • imageview
  • iphone
  • remote

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() });

    — answered November 21st 2011 by Corey Snyder
    • I don't know if this solved the original issue but it really worked for me. Thanks a lot Corey !

      — commented January 30th 2012 by Ago Stino
    • THANK YOU!!!!! This has been driving me crazy. It would be really nice to just have a refresh method, or clearcache or similar.


      — commented July 24th 2012 by Tom Gimpel
  • 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'));

    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? :(

    — answered July 19th 2010 by Raul Magdaleno
  • 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;
                        x = e.x;
       x=x - e.x;
                     else if(x>20 && z<total-1){

    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.

    — answered July 19th 2010 by Daniel Lim
    1 Comment
    • Thank you, for ScrollView problem is a solution.

      — commented July 19th 2010 by Raul Magdaleno
  • 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.

    — answered July 18th 2010 by Daniel Lim
  • 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!

    — answered July 19th 2010 by C. T.
  • 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() ?

    — answered July 19th 2010 by C. T.
    • There's no scrollview close method, chances are it going to crash your app.

      One thing i notice upgraded to 1.3.x is be very careful with methods and functions not available for that particular object. It's not that forgiving and would crash your app.

      For instance, in the past, i used to have "textAlign" on imageView and View objects (textalign is not available on those objects), it never crashed and would ignore, app runs smooth. Now with 1.3.x, it would crash the app unexpected after few clicks, remove all these typo and so far, so good.

      — commented July 19th 2010 by Daniel Lim
    • Daniel, but have you ever tried to load a lot of images? Whether in a WebView, imageview, with or without ScrollView, etc? It is released from memory?

      — commented July 20th 2010 by Raul Magdaleno
  • 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).

    — answered July 19th 2010 by Raul Magdaleno
  • 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 :/

    — answered July 19th 2010 by Raul Magdaleno
  • What size are the images? The iOs SDK recommend not to use images bigger than 1024x1024

    — answered July 19th 2010 by Dan Tamas
    1 Comment
    • 320x480

      — commented July 20th 2010 by Raul Magdaleno
  • 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. :?

    — answered July 21st 2010 by Raul Magdaleno
    1 Comment
    • I'm facing this problem as well, I found this post: http://iphonedevelopertips.com/memory-management/images-and-caching.html

      — commented March 19th 2011 by Alexander van der Werff
  • nobody has been able to test it?

    — answered July 24th 2010 by Raul Magdaleno
  • Did anyone find a solution to this? I'm running into the same issue with a video player.

    — answered January 31st 2011 by Andrew Mussey
    1 Comment
    • I would like to be able to clear out the image cache when my Apps main window is closed, so not to consume large amounts of memory even when the App is closed.

      — commented February 14th 2011 by Chris Brooks
  • 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 ?


    — answered February 25th 2011 by Jeremy Sculfort
    1 Comment
    • I'm also having the Same Problem with a webview. If too Many Images have been loaded into the webview the Cache seems to be full and all Images disappear. Is there really no way to Control the cache manually?

      — commented March 2nd 2011 by Torben Dierks
  • 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?

    — answered June 11th 2011 by Dave F
  • I still issue this kind of problems. Anyone have a solution?

    — answered December 13th 2011 by Umberto Gonnella
  • 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

    — answered December 13th 2011 by Corey Snyder
  • 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


    — answered July 18th 2010 by Raul Magdaleno
    1 Comment
    • Raul, what do you mean when you say WebView works "better"?

      — commented April 28th 2011 by Rakesh Shankar
  • Did anyone try saving the images locally and then using them instead of opening from remote?

    — answered July 20th 2011 by Idan Jan
  • 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

    — answered July 18th 2010 by Dan Tamas
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.