<p>My website is entirely flash based, it moves around a 3D model which was given to me as chunks of video that I've converted to FLV files. I'm using the FLVPlayback component to control the video inside of my program. While running memory checks using System.totalMemory I've noticed that whenever a video is loaded, it will eat up a chunk of memory and even when I remove all the event listeners from it(they are all weakly referenced), remove the component from its parent, stop the video and null the component instance, it still will not give that memory back.</p>

<p>This has been bothering me since I started working on this project because of the huge amount of video a user can potentially instantiate and load. Currently every video is loaded into a new FLVPlayback instance whenever it is required, but I have read that perhaps the best way to go about this problem is to simply have a global FLVPlayback instance and just reload the new video into the old instance, that way there would only be one FLVPlayback component in the application's memory.</p>

<p>Has anyone else run into this problem as well? Have you found a better solution than using a global instance that you just re-use for every new video? </p>

[{'answer_id': 25899, 'author': 'aib', 'author_id': 1088, 'author_profile': 'https://Stackoverflow.com/users/1088', 'pm_score': 2, 'selected': True, 'text': '<p>You can\'t help the memory problems much until Flash adds destructors and explicit object deletion, unfortunately. See this thread:</p>\n\n<p><a href="https://stackoverflow.com/questions/34/unloading-a-bytearray-in-actionscript-3">Unloading a ByteArray in Actionscript 3</a></p>\n\n<p>There\'s a limit to how much memory Flash applets can use; the GC seems to fire upon reaching that limit. I\'ve seen my memory-easy applets use as much as ~200MB, just because they run for hours on end and the GC doesn\'t want to kick in.</p>\n\n<p>Oh, and I don\'t think using a single instance is an elegant solution, either. Currently I just write a dispose() function for my custom classes, waiting for some day when it can be turned into a proper destructor.</p>\n'}, {'answer_id': 25901, 'author': 'Ed.', 'author_id': 522, 'author_profile': 'https://Stackoverflow.com/users/522', 'pm_score': 0, 'selected': False, 'text': '<p>Unfortuantely, thats just the way flash handles it.  Not particularly smart, but it works for most people.</p>\n'}, {'answer_id': 25996, 'author': 'grapefrukt', 'author_id': 914, 'author_profile': 'https://Stackoverflow.com/users/914', 'pm_score': 2, 'selected': False, 'text': '<p>I\'ve never really liked the components, they\'re a bit dodgy. This particular problem seems to be common, and the somewhat annoying solution is, as you\'re suggesting, to only have one FLVPlayback and reuse that. </p>\n\n<p><a href="http://www.sakri.net/blog/2008/07/10/flvplayback-doesnt-unload-flvs-becomes-memory-hog/" rel="nofollow noreferrer">Here\'s a blog post about it</a></p>\n'}, {'answer_id': 26325, 'author': 'vanhornRF', 'author_id': 1945, 'author_profile': 'https://Stackoverflow.com/users/1945', 'pm_score': 1, 'selected': False, 'text': "<p>Thanks for the responses, the links to the other blog questions were helpful as well, I had read all of Grant Skinner's info on garbage collection too, but searching through those links and going back and re-reading what he had originally said about GC helped refresh the old noggin. In addition to nulling and re-instantiating that single FLVPlayback component, I also realized that I wasn't correctly unloading and destroying my Loader instances either, so I got them cleaned up and now the program is running much more efficiently. I would say the memory usage has improved by around 90% for the site.</p>\n<p>@aib I will admit the single instance solution isn't elegant, but because flash just won't let go of those FLV files, I'm kind of stuck with it.</p>\n<p>@grapefrukt I detest the flash components, they typically cause more grief than time saved, however in this case I had a lot of cue points and navigation stuff going on with the video files and the FLVPlayback component was the best solution I found. Of course I'm still fairly new to the ActionScript world so perhaps I over-looked something.</p>\n"}, {'answer_id': 1883423, 'author': 'James', 'author_id': 229086, 'author_profile': 'https://Stackoverflow.com/users/229086', 'pm_score': 1, 'selected': False, 'text': "<p>From what I gather after a lot of testing is that flash dynamically loads in libraries and components as needed but never garbage collects that data. For instance, if I have a website or an Air app that uses the FLVPlayback component, the actual component and libraries associated with it aren't loaded until a new FLVPlayback() instance is created. It will then load in the library and component into memory but you will never get that space back until the program /  website is closed. That specific instance with the video inside of it will get garbage collected and release some memory as long as you remove listeners from it, take it off the stage, and set it to null.</p>\n\n<p>Also, if you are doing individual videos, the VideoPlayer is much lighter weight, and cleans up nicer.</p>\n"}]
['https://Stackoverflow.com/questions/23439', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1945/']