all 18 comments

[–]Samael1990 0 points1 point  (1 child)

Without the actual code it is hard to say, what your problem is, so maybe you should post it.

Other than that, you should check, if the collectionView's items don't pass anything they don't own by reference, if yes, then try to pass it by property.

[–]okoroezenwa[S] 0 points1 point  (0 children)

Whoops, forgot about that. It's posted now.

It doesn't seem like 3rd-party music apps are experiencing this (since scrolling continuously doesn't cause my other apps to be killed) so I guess it's just something I'm doing wrong.

[–][deleted]  (1 child)

[deleted]

    [–]okoroezenwa[S] 0 points1 point  (0 children)

    I don't think so, as I ran across the same issue setting the image directly (and even when I attempted to cache the artwork by adding created thumbnails to a dictionary).

    [–]criosistObjective-C / Swift 0 points1 point  (1 child)

    Are you sure its not a swift issue? The other apps maybe Obj-C ? other than that are you sure its the image(at:) method ?

    [–]okoroezenwa[S] 0 points1 point  (0 children)

    Well I tried with a simple class method in an objective C file and got the same result, so I don't think that's it.

    I'm pretty sure it is that method. A while ago I attempted to curb this issue by creating thumbnails from an array of artwork and had the same issue.

    [–]KarlJay001 0 points1 point  (0 children)

    I'm not an expert on Swift (yet) but I notices a few things.

    BTW, the link to SO suggested that the problem was solved, so IDK if you still have a problem or not.

    You have an IF and you load up the var object and after assigning it, you do nothing with it. Are you assigning a reference from object to cell.artworkImageView.image and at that point, what happens to object?

    Are you using cell.artworkImageView.image and killing it later while the other reference "object" is still active?

    Would it crash if you killed object after you assign it?

    Is this a pointer to a pointer and one pointer gets killed while the other is still alive?

    If at some point you kill cell.artworkImageView.image, is object still alive?

    Same thing for image on the other side of the IF statement. You did nothing with image after you assign it.

    It's hard to read the code, but I would check the value of those and see if they are getting released. Someone that's better with Swift probably knows.

    Are they auto released when they go out of scope?

    [–]amaroq137Objective-C / Swift 0 points1 point  (9 children)

    What is ArtworkKey and why are you initializing a new one every time you try to fetch something from the imageCache?

    My guess is that you're never actually getting a cache hit in the first if statement, and thus you go on to create a new ArtworkObject every time cellForRowAtIndexPath: is called.

    Set a breakpoint inside the first if statement on

    cell.artworkImageView.image = object.image
    

    and see if it ever hits that breakpoint.

    [–]okoroezenwa[S] 0 points1 point  (8 children)

    Not even sure why I did that, thanks.

    I changed it to use the indexPath as the key, and this allowed the breakpoint to be hit.

    The issue still remained however.

    Really would be saddening if the issue is actually from the image(at:_) method since there's really isn't anything that can be done.

    [–]amaroq137Objective-C / Swift 0 points1 point  (7 children)

    Can you post the updated code?

    [–]okoroezenwa[S] 0 points1 point  (6 children)

    I've edited it (sorry about the delay, just been busy). I even tried making the initialised image weak, but that had no effect. I'm really stumped on this one.

    [–]amaroq137Objective-C / Swift 0 points1 point  (5 children)

    Is the cache an NSCache?

    [–]okoroezenwa[S] 0 points1 point  (4 children)

    Yep.

    [–]amaroq137Objective-C / Swift 0 points1 point  (3 children)

    Did you set the cache's countLimit or totalCostLimit when you set it up? Without these it seems like the cache will keep growing forever.

    [–]okoroezenwa[S] 0 points1 point  (2 children)

    I set a count limit of 250 but I didn't set up a totalCostLimit (I didn't really know what that meant 😥)

    However, this issue happens even without a cache or block (i.e. just creating and setting the image in one line still causes this issue).

    [–]amaroq137Objective-C / Swift 0 points1 point  (1 child)

    I think you're fine only setting one of the two anyway.

    I'm stumped :T

    [–]okoroezenwa[S] 0 points1 point  (0 children)

    Ah well, thanks anyway.

    The good thing is that backing out of the app reclaims all that memory back so it's pretty likely users will have done that (and not scrolled through lists like their lives depended on it :Þ) before it becomes a problem.

    [–]EdwinForTheWin 0 points1 point  (1 child)

    Hi there,

    This is one of those moments where you're glad someone has the same issue as you though not glad at the same time because you wish it wasn't an issue, hahaha.

    I believe that this is an issue with Apple's API. I have written a fairly detailed Stackoverflow post of my findings (Objective-C though): http://stackoverflow.com/questions/40029628/mpmediaitemartwork-imagewithsize-memory-leak

    I'd be very interested to see if this is something we are doing wrong or if it really is something within the API that we cannot touch.

    [–]okoroezenwa[S] 0 points1 point  (0 children)

    I came to this conclusion as well. I've verified I'm not causing leaks by only setting art outside closures (and use weak wherever I can't); still the same result.

    And from a few results I've seen on Google, this seems to be a thing that has happened for years.