SwiftyGiphy icon indicating copy to clipboard operation
SwiftyGiphy copied to clipboard

Unbounded memory issues

Open shalins opened this issue 5 years ago • 6 comments

First of all, thanks for developing such an awesome repo–I've been using the pod like crazy and appreciate all the work you guys have done with this.

Unfortunately, I've been having a lot of memory issues with using this. 1) as I scroll down further and further, my memory increase is unbounded. 2) that wouldn't be a problem except this memory is never freed when I pop/dismiss the SwiftyGiphyViewController. All the mallocs and CGImageData are saved in memory and none of the objects are ever released.

image

I've spent 50-60 hours tracing through the code line by line and trying to figure out how to fix the issue but I haven't been able to find it. At first, I thought it was something simple with the collection view objects not being correctly dereferenced, then I tried looking deeper into each of the components that make up each cell (all the subviews, etc). I tried deinit-ing latestTrendingResponse and latestSearchResponse and even every individual element inside (as well as pretty much any other place I could find saved gifs). I've tried keeping track of other things such as how many CornerRoundingViews were kept in memory at different points in time. I've spent many frustrating hours in Instruments to no avail.

It would be beyond awesome to be able to use this repo in production. If you guys have some time, would you be able to look into fixing the memory issues? Perhaps you guys might be able to fix it more quickly than I'd be able to since you guys are the ones who actually wrote the code.

Thanks so much!

shalins avatar Apr 13 '19 10:04 shalins

Bump (it'd be so helpful if you could take a look at this for even like 15-20min, I'd be more than happy to fix it myself but it's difficult to debug since I didn't write the code)

shalins avatar May 06 '19 23:05 shalins

Bumping this again

shalins avatar May 28 '19 17:05 shalins

Guys cmon would really appreciate the response and help

shalins avatar Jul 14 '19 07:07 shalins

It has literally been months

shalins avatar Jul 14 '19 07:07 shalins

@shalins I am so sorry for such a late response but have been looking into this issue since the first bump. If you are able to find a fix to the leak I will be happy to merge a PR, however, I am also having trouble pinning down the best approach to the issue that I see. I initially thought it may be related to the SDWebImage library and the image cache it maintains not being cleared. However, when looking at the memory graph hierarchy I see a few issues that seem to point directly to the SDWebImage decoder. That is where I see most of the retain cycles that are causing the memory leaks. I have tried a few approaches to clear these retain cycles, however, those attempts did not bound the memory. Many of the mallocs are coming from the call here and I have yet to figure out a solution that does not require a rework. Again I am so sorry for the late response and will keep you updated as I search for the solution.

ulmentflam avatar Sep 16 '19 07:09 ulmentflam

@ulmentflam Thanks for the response! Yeah, I was also able to point to the same line causing all the mallocs but I didn't really know how to fix it from there. I tried a bunch of different things that didn't end up working.

My temporary solution was just to not allow pagination so the memory usage wouldn't keep increasing as I scrolled. But obviously this solution doesn't actually fix the problem and using the search bar to search for new gifs still mallocs space.

I will still keep an eye out for some way to fix it when I'm running through the code but I appreciate you looking into it and let me know if you do come up with a fix!

I would love to use the repo in a production app :)

shalins avatar Sep 17 '19 23:09 shalins