objective c - iOS - How to avoid memory leak when saving and loading images to display in UITableView? -


so more of conceptual architecture question. i'm making messaging app in ios. devices can send image messages. saving custom message objects (which include images) disk using nscoder protocol. want remove messages memory when don't need them (i.e. when user logs out , disappears users list view). appropriately encoding user's messages disk, , loading them when user re-appears. however, on messaging view (a dynamic uitableview each cell displays message content), image content of messages cached within uiimageview subview.

so, creating duplicates of images when load messages disk. every time user logs out , in (i.e. disappearing , reappearing), associated messages saved , loaded disk (recreated objects), , memory usage creeps upward once go private message view , scroll way in order display messages.

ultimately, want clean cache of message images can free memory when user no longer around. have reason saving messages locally; question is: best design saving messages/images disk, removing them cache memory, reloading them when need populate dynamic uitableview?

i'd advice use ready caching library like: sdwebimage, fastimagecache or haneke. of them both using disc , memory cache, improve speed of tableview , decrease number of download requests.

you can of course make custom solution, won't work written during months , tested via many developers. if want to, i'd suggest take 1 of these libraries , start considering they've done make 'speedy'.

this way save url in message instead of full image. these libraries check url, understand have image in memory cache , load it. don't have store in array of objects nor download again or save on disc.

keeping message objects on disc seems weird, slow - better use database - coredata/mantle/fbdb etc, that's decision :) storing on disc makes messages easy reverse engineering attacks , isn't safe.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -