Search code examples
javascriptobjective-cipadmemoryallocation

Xcode: Allocation and Leak when uiwebview is loading its content?


I have a problem with my application that is using uiwebview to load the html5 page which has a canvas with some images on it. I don't know when the html5 load statically but when i enlarge the image on the canvas with touch event from JQuery, the memory allocation starts to increase so quickly from 2mb to 8 or 10 mb. The high memory allocation won't decreased even though the uiwebview got released.

Does anyone have met this issue?


Solution

  • There is no reason to believe this is an actual memory leak. It's most likely WebKit caching data. The relevant thing to look for is weather the memory is released when the app receives a memory warning. You can force memory warnings using this snippet:

    [[UIApplication sharedApplication] performSelector:@selector(_performMemoryWarning)];
    

    Only do this when debugging! If you submit an app with this method invokation, it will be refused by Apple.

    You can create a button to trigger the memory warning, or use a timer to trigger it every few seconds. When the memory warning is triggered you should see the memory being released (most probably even if the web view has not yet been released).