-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leaks caused by ReaderConverterCallback? #5
Comments
have you found any solution for it?
Have you found any solution? |
Not yet. |
fix issue syedhali#5 memory leak while in paused state
Did you ever find a way to deallocate the pointers here? I've been playing around with this a bit and have run into the same issue
Did you ever find a way to deallocate the pointers here? I've been playing around with this a bit and have run into the same issue |
Nope, I haven't looked into it since then. |
Hi there, I’ve experienced the same memory leak and would like to tell you about my solution.
I use var packetDescs:[UnsafeMutablePointer<AudioStreamPacketDescription>?] = []
var packetDatas:[UnsafeMutableRawPointer?] = []
after allocating memory for data I call packetDatas.append(ioData.pointee.mBuffers.mData) and after allocating memory for the description (if there is one) I call packetDescs.append(outPacketDescriptions?.pointee)
immediately after usage func cleanupConverterGarbage() {
packetDescs.forEach { (desc) in desc?.deinitialize(count: 1); desc?.deallocate() }
print("deallocated \(packetDescs.count) packet descriptions")
packetDescs.removeAll()
packetDatas.forEach { (data) in data?.deallocate() }
print("deallocated \(packetDatas.count) packets of data")
packetDatas.removeAll()
} I saw memory leaks in profiler without fix. They are gone when fixed. FlorianAtNacamar ![Uploading AS_fixed_noLeaks.png…]() |
The issue seems fixed in Ventura. |
@FlorianAtNacamar Interesting solution for the memory leak. I've added your change, but am running into the following issue with a .mp3 file. The following line is crashing:
How can we fix that? |
It seems to me that the memory issue is we are downloading the whole file into memory... maybe a better solution would be to only buffer some % of the file ahead (maybe adjusting based on network conditions) and drop all the packets from the reader that have already been played? Or we could make a file caching system if we want that data to persist temporarily. In long audio files the demo app simply won't play because it ran out of memory. |
In my implementation what was piling up memory were not a continued downloading but the timer scheduling the buffer. The author indeed commented that it was not an ideal solution. I've managed to use the completion block of the schedule function to pull the next reading instead and it works well for me; the memory issue is gone. ` func scheduleNextBuffer() {
`
I hope this solution could be of some help. This project is awesome and saved me a lot of time. Thank you to the authors. |
Hi, first I'd like to say how great this framework is. It saved me a lot of time, thank you.
I've noticed that once I called
play()
method on theStreamer
class, the memory usage was growing rapidly in my app. To check whether it's a problem on my side I downloaded your example project and profiled it.It seems there are memory leaks in
ReaderConverterCallback
caused byUnsafeMutablePointer
that is never deallocated.I tried to set the streamer's URL to a longer audio file (>1 hour) and the used memory was more than 500MB in about a minute even though the audio file was only about 50MB big.
Steps to reproduce
EDIT
I think I might understand the problem here. The memory usage is growing even though the audio was paused - the
read()
method is reading empty packets and allocating new memory for the buffer here and hereI'm not really sure how and when should I deallocate the pointers though.
The text was updated successfully, but these errors were encountered: