Huge memory leak somewhere in AVFoundationMBS


It looks like there’s a huge memory leak in AVFoundationMBS. Even the example project (Extract video frames) shows this issue to me.

I tried with several formats of video files (.m4v, .mov, .mp4, .avi) and always get the same behaviour: while frames are being extracted, I can see the process VTDecoderXPCService’s memory growing in activity monitor. After only ten seconds, it uses 2 GB of RAM. After around a minute, it uses 25 GB of memory.
Memory pressure grows and finally Mac OS presents the dialog “Your computer has run out of available memory. Please force quit some applications below:” (translated in english by me here, but it’s a known dialog). At this stage, the debug app hangs.

I’m surprised it’s not an already-reported problem, as I can reproduce it trivially; only needed thing is a video file that’s not too short and the “Extract video frames” project in the MBS examples.

Mac OS ventura, latest Xojo.
My project is obviously severely impacted (not useable); I’m open to provide any information that would allow this problem to be fixed. I’m not sure which class leaks the memory.

It might be a good idea to also email Christian directly in case he misses this post.

Possibly. With so many channels to report a bug, it’s not trivial to choose the correct one.
Like I usually do, I’ll first wait some time here and, in case of no answer in one day, opt for another channel.
Thanks for the advice.

Thanks for reporting.
I found an issue and fix it for pr5.
Maybe tomorrow, I upload new plugins and you can try it.


Thank you :slightly_smiling_face:

Does the fix work?

MBS Xojo Plugins, version 23.3pr5

1 Like

Yes, it seems to work flawlessly, thank you.

In fact, I already tried some hours ago, but there’s another memory leak in my code so I started tracking it before answering here. The example project now works fine with the change you made, but there’s another issue, apparently in NSImageMBS.

When processing frames, this code also produces big memory leaks:

//SourceImage is an NSImageMBS
Var x,y as integer


Var Pict As Picture=SourceImage.CopyPicture

//Use Pict for drawing

But this one does not:

//SourceImage is an NSImageMBS
Var Pict As Picture=SourceImage.CopyPicture
Var x,y as integer

//Use Pict for drawing

In other words, if I access the width or height of the NSImageMBS object before using CopyPicture, I’m getting huge leaks (similar to those I described in my initial post). If I use CopyPicture first (even doing nothing with the returned Xojo picture) and then access NSImageMBS.width or NSImageMBS.height, the leaks don’t happen.

The current issue has workarounds (use CopyPicture first), but I wanted to let you know about it.

Something is strange here and it may be something else.

e.g. you may need to use NSAutoReleasePoolMBS class here and just make a new pool replacing the old one every 10 frames or so.