Slow Memory Leak using Active Object with Active Direct Show.

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • Hello, I've encountered a strange issue with my current game. I'm getting a slow memory leak as I progress through the frame and I don't know why.

    In my frame, the player is able to "move" throughout the environment in a psuedo-free roam way by playing pre-rendered movement animations in video format. There is an active object in the frame that has 34 animations, each containing anywhere from 3 to 8 frames. The player is able to move and turn via the video animation via the active direct show object, and then the active direct show is moved beneath the active object, which displays one of these frames in one of these animations.

    Please login to see this attachment.

    The problem I have is that as the player goes through these actions of video playing -> move beneath other active object image, the memory usage creeps up by about 9-11 Mb each time.

    Here is a video demonstrating what I'm talking about.

    Please login to see this media element.

    As you can see, the memory starts at about 500 Mb, but as I continue, it creeps up to 650 MB when everything in the frame is resting. When I tested the movement gameplay a while ago as I first found this out, it just kept creeping up, eventually even up to 1400 Mb!

    I've searched through my code for what could be causing this, and I couldn't find any obvious (to me) problem with it. I don't believe I'm creating duplicates of things, and I've already tried changing my Active Direct Show object to be a version specifically fixed from its own memory leak issue.

    I'm confident it has something to do with the active object that contains all the animations. Perhaps there is some process going on behind the scenes that keeps eating up more RAM as each of the images in that object are displayed. Maybe it has something to do with resampling, as I've looked at in this old post?: Please login to see this link.

    Having the object set to "Load on Call" doesn't help, neither does unchecking that option. When I don't create the active object at start, the memory is at about 87 Mb, so I know that the bulk of the normal 500 Mb memory is dedicated to most of the active object's images already being loaded in.

    In total, the amount of information the active object should need is about 500 Mb on it's own, which is fine and expected, but I don't believe that number should be growing as I use it.

    Here are my settings for my application if that's needed:

    Please login to see this attachment.


    Please login to see this attachment.


    And here are the settings of the active object in question:

    Please login to see this attachment.


    Please let me know if you guys need more information.

  • I could definitely be wrong, but this is my guess:

    1. Your videos are in a compressed format. Either MPEG video, or series of still images using a compressed format like PNG. When looking at the total combined filesize of these compressed files, they appear to be 500MB.

    2. Just as Windows must decompress a ZIP to open the files inside, Fusion must decompress your images to display them. So Fusion decompresses them as it goes. Effectively, it turns each frame into something like a BMP (which, although it appears visually identical to a PNG, is much larger).

    3. As you progress through more of the game, Fusion decompresses more and more of images/videos, storing them in memory as it goes. Eventually, it will have stored close to the full amount of decompressed data from your videos, which will be larger than the total compressed size of the files themselves.


    If my guess is correct, then perhaps it might help to break up your videos into smaller chunks, rather than using a single active with all 34 animations in it. Then, at strategic times, you could destroy and re-create some of those chunks in the background, to force Fusion to purge the decompressed data it's accrued from them and reload the tidy compressed versions.

    Also, if you don't have the 2.5+ DLC, I believe it contains some sharper memory management, so getting it might help your situation, though I actually have no idea if it would help in this particular situation at all. Though probably worth trying, because the many other features in 2.5+ are fantastic and will make your life easier in various ways, so it's a highly recommended upgrade anyway.

    Please login to see this link.
    My Fusion Tools: Please login to see this link. | Please login to see this link. | Please login to see this link.

  • So I did more testing. I thought for sure that I had Fusion 2.5+, but turns out I didn't, so I bought that. The problem didn't go away, and so I used a test frame and only used the active object with the 34 "animations", (really they're just sets of still images for the player to see when none of the actual video animations are playing.)

    What I found is interesting. I coded it so when I pressed the space bar, the object would go to the next "animation" (set of still images).

    Here's a video of what happened:

    Please login to see this media element.

    As I progressed through the active object animations, the RAM usage built up, but eventually once I got to the end, the RAM decreased all the way back to about 500 Mb again!

    When I used the arrow keys to scroll through the still images in one of the animations, the RAM went up, but didn't go down. In all honesty, I'm fine with that if the RAM eventually "resets" for each "animation" (set of still images). The player also wouldn't be able to actually move this fast in the environment in actual gameplay.

    So really, the active object doesn't necessarily seem to be the real culprit for why the RAM usage doesn't go down. So my only guess is that there is something going on with the Active Direct Show Object.


    This is an example of the first part of how the video transition is played.
    Please login to see this attachment.

    There is a dance of code between ordering and such of the still images from the active object and the active direct show object in order to avoid the black screen at the start of every video that comes from loading it in, but I don't think that's necessarily affecting the RAM build up.

    The video transition files are also accessed with a few strings that change depending on the situation, but ultimately I checked "Include External Files" in the application settings, because the total amount of video files I need to access is probably too much for binary data alone, so I understand I'll need to create an install program.

    Finally, the "Play Swivel 2" is a set of instructions shown below:

    Please login to see this attachment.

    My best guess is that something is going on with the active direct show object where some of the video information gets stored or is left over after each video plays. In the first video I posted, there is a jump of about 100 Mb when playing the video, but that eventually goes down, but not all of it does. There seems to be left over RAM usage that unlike the test frame, stays in place, and I'm wondering if I'm not properly using the active direct show object when it comes to playing many types of video files.

    Should I destroy the active direct show object after it is used? Or should I "close" the video after it's done or something?


    [End note about compression on my files]

    The still images I'm using are in PNG format, and as far as I know they should only have about 15% "compression" on them from being rendered in Blender.

    The video files I'm using are compressed in the "Perceptually Lossless" option in the Blender 3.1 Video Sequence Editor, and are saved to an AVI format.

  • Some more info:

    I built the current version, and verified that it does continually leak memory according to the task manager.

    I've been messing around with destroying the active object and re-creating it in order to release the memory, but that doesn't seem to be working. Also I've tried using the "close video" option in the active direct show, but no results there either.

    Such an odd issue.

  • Doesn't seem to work all that much, the bulk of the left over memory remains. I don't know if there's some kind of option in the settings that keeps the memory of objects even if they're destroyed.

    It is really odd, it makes me think that the direct show object is storing some kind of information from its access of each video file, and that's what is going on. I'll probably try a few different things and change my approach.

    I've tried a lot of things, at this point I might as well upload the .mfa for people on here. I won't be able to do that though until tomorrow.

  • Okay I did more testing, and I had some interesting discoveries, and possibly an epiphany.

    I made a second test frame where I only had the active direct show object, and I then wrote some code to play a small amount of the video files , each one based on what the value of a counter was at the time. (I also included a limit condition so it wouldn't perpetually load and play over and over again). It turns out, the memory leak that is present in the original frame doesn't occur. After playing about 40 of the video files, one after another, the RAM only fluctuates by about 2 Mb from the initial amount.

    So it's not solely the active direct show object, nor is it solely the active object. The active object alone increases RAM usage, but also releases it. Direct Show alone doesn't perpetually increase it. Yet these two together in my original frame with my original code keeps building up the RAM the more I use it.

    And here's where I realized something about my code.

    Please login to see this attachment.

    This image shows what I originally coded: the player would press "W" and a video would play.

    But then I changed it to this:

    Please login to see this attachment.

    Using the Key Object, I managed to let the player seamlessly "move forward" by keeping "W" pressed down at the end of the video file, so that it would immediately play the next one.

    The problem I see is that there is no limiting condition there, so perhaps this set of instructions are being perpetually done for a while, even if I'm only pressing the key for a short second.

    I don't know if this is actually happening, and I don't know why this would result in the memory leak, since nothing is being created or added in the resulting process, but who knows, I'm out of ideas of what could be causing this.

    I'll see if it fixes it tomorrow.

  • Please login to see this picture.

    This might be ok because of conditions #2, #3, and #4. Without those conditions, it would be firing ad nauseum 60 times a second or so, which would certainly be a bad thing. The Key Object's is key down condition is effectively the same as Fusion's native repeat while key pressed condition. (though only the Key object can detect keys even when your application is minimised, but that's probably not relevant to this project). But because of conditions 2-4, it should only fire once per video (ie. it sets Animation to 1 and Counter to 1, which will prevent the event from refiring immediately).

    I haven't used the Direct Show object much, so don't really know how it works, but this makes me wonder:

    Please login to see this picture.

    You're loading a video from disk every time the user moves. Presumably, the same video(s) will be loaded multiple times if the user retreads the same locations. Perhaps there's some sort of overhead that get loaded each time, resulting in the memory leak. You could test this by loading the same video over and over again with a keypress, and seeing if the RAM fluctuates.

    What would happen if you had separate Direct Show objects, each with a single video loaded in to it (once, and never reloaded again), and switch between those objects rather than overwriting the video in the same object each time - does the RAM still fluctuate? (Try testing with 5 or so - no need to set up all 34). Just throwing up ideas.

    Please login to see this link.
    My Fusion Tools: Please login to see this link. | Please login to see this link. | Please login to see this link.

  • It's a good thing I installed 2.5+, because I stumbled upon a fix!

    By setting my display mode to Direct3D 11,

    Please login to see this attachment.

    And unchecking use Media Foundation with DirectX 11 (Because the videos play erratically if this isn't done)

    Please login to see this attachment.

    It now has no memory leak!

    Please login to see this media element.

    By the end of the video, the RAM is stable at about 515 Mb, and I confirmed this with a build using Task Manager.

    So there was some kind of Process with Direct3D 9 that caused some kind of memory leak with all the code I had set up, but 3D 11 fixed that issue at some point in its code.

    I'm happy that this means I don't have to segment this frame up into small frames, because that was my first approach to making this. I had 11 frames, that the player would jump through depending on where they were. But I had to discard this approach because there was a very noticeable pause when moving frames (about 2 seconds), which was not good for keeping the movement smooth enough.

    I'm not sure what else I would've done, since destroying either objects was difficult to code well with my systems, and didn't immediately release any memory, (making it easy to build it up and crash the whole application)


    Thanks for your help and insight Volnaiskra! I really thought I had been using 2.5+ all this time, but I apparently wasn't, and that version had the fix for my issue.

  • Excellent news! And it must be a relief that the solution wasn't a super-complicated and/or painful one.

    Now that you have it, do familiarise yourself with some of the other Please login to see this link. too, as they're excellent. Many of them are ones I could no longer imagine living without (eg. Find All, Custom Qualifiers, Select All Instances, 260 altVals, Base Frame, Child events...)

    Please login to see this link.
    My Fusion Tools: Please login to see this link. | Please login to see this link. | Please login to see this link.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!