neekeetab / CachingPlayerItem

Play and cache media content simultaneously on your iOS device
MIT License
520 stars 89 forks source link

Memory Issue #42

Open ztrktunahan opened 2 years ago

ztrktunahan commented 2 years ago

After a certain number of videos have been downloaded, the application is terminated by memory error. For this, can we save the downloaded data to disk instead of memory?

If we can't do this, can you help us how to remove the downloaded data from memory? (I know that the data is not cached, but as long as the application is open, the downloaded data is kept in memory, causing memory issue)

neekeetab commented 2 years ago

The data is stored in ResourceLoaderDelegate.mediaData. Technically, when you lose the reference to the CachingPlayerItem it should be released from the memory along with all of it's internals.

There may be memory leaks causing the issues you're describing. I would add deinits to ResourceLoaderDelegate and CachingPlayerItem, make sure that they get called, and troubleshoot from there.

If you find there's a bug in the implementation, please report it

ztrktunahan commented 2 years ago

I tried it but can not achieved this. Can you give example to add &c call deinits to ResourceLoaderDelegate and CachingPlayerItem.

mohamedrafi-rapid commented 1 year ago

I also want to remove the cached items. Please help

neekeetab commented 1 year ago

There's no caching done by CachingPlayerItem. It only gives you the raw Data via a delegate, and it's up to you how to cache it (and how to delete it from your cache).

NickBrinsmade commented 1 year ago

Hi, so I'm working in SwiftUI. I added prints to the existing CachingPlayerItem class and then the contained class ResourceLoaderDelegate. In my case it looks like the CachingPlayerItem deinit is fired every second--is this the correct behavior? For every deinit CachingPlayerItem that is fired, there is a ResourceLoaderDelegate deinit that is fired as well.

I'm getting a Memory error in the processPendingRequests() function when it tries to map the pending requests.

Not sure why exactly this error would be happening. All I've done is replaced all my existing AVPlayer(url:) structs with AVPlayer(playerItem:) structs instead. Should the cache be working in this situation? Not sure how to continue debugging because I don't understand the module 100%. Any help is much appreciated!