Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How do you unload memory from a movie called from the StreamingAssets Folder?

Discussion in 'iOS and tvOS' started by DFiable, Jul 7, 2012.

  1. DFiable

    DFiable

    Joined:
    Mar 3, 2012
    Posts:
    27
    I have a movie playing in the first scene of my game, however it uses and continues to use up RAM and consequently the game runs poorly on low memory devices like the iPhone 3GS. Since I'm using this to call the movie ( Handheld.PlayFullScreenMovie ("MyMovie94.mp4", Color.black, FullScreenMovieControlMode.CancelOnInput); ), I created a StreamingAssets Folder which holds the file "MyMovie94.mp4"
    How do I unload memory that is called from a StreamingAsset Folder in Unity? Remember this file is not in my Resources Folder. Anybody have any ideas?
    Thanx



    I found this(below) in the Unity Manual Which shows me the path to the file on IOS. Does anybody know the next command to delete the file from memory?


    Streaming Assets
    Most assets in Unity are combined into the project when it is built. However, it is sometimes useful to place files into the normal filesystem on the target machine to make them accessible via a pathname. An example of this is the deployment of a movie file on iOS devices; the original movie file must be available from a location in the filesystem to be played by the PlayMovie function.

    "Any files placed in a folder called StreamingAssets in a Unity project will be copied verbatim to a particular folder on the target machine. On a desktop computer (Mac OS or Windows) the location of the files can be obtained with the following code:-

    path = = Application.dataPath + "/StreamingAssets";

    On iOS, you should use:-

    path = Application.dataPath + "/Raw";


    "
     
    Last edited: Jul 8, 2012
  2. techmage

    techmage

    Joined:
    Oct 31, 2009
    Posts:
    2,133
    Memory being used up should not impact performance in anyway, as in frames per second. Memory being used up results in the game crashing due to out of memory errors. If your game isn't crashing, then memory isn't really an issue.

    As for the getting rid of the memory. I have not done thorough testing on this, and have actually been looking into and wondering about this myself as of late. But it seems to me that ever since ARC went into place (automatic reference count) iOS apps will hold allocated memory in place until it absolutely must release it. I am not sure if that is true entirely. But the video player on Unity may be exhibiting this kind of behavior.

    Are you opening a movie, then closing it, and is your app then getting memory warnings and not releasing that memory? If so, then something is wrong. But if your app isn't getting out memory warnings, it may not be releasing unneeded memory because it doesn't have to... Again, not 100% sure if thats true, just somehting I've noticed in some of my companies newer ARC apps, does anyone else know more about this?
     
  3. DFiable

    DFiable

    Joined:
    Mar 3, 2012
    Posts:
    27
    My game is not crashing nor am I receiving memory errors, but when I remove the movie scene from the "build", the game plays smoothly. So I made the assumption it is memory drag. If the movie scene is IN the "build" it is unacceptably jerky motion. The game has a continuous forward motion so it's very noticeable. Is this something other than memory management? Any ideas would be appreciated. Thanx for your input.

    The movie is 2.4 MB.
     
    Last edited: Jul 9, 2012
  4. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    it sounds more like the movie is not properly terminate
    in which case it hooks up gpu power
     
  5. DFiable

    DFiable

    Joined:
    Mar 3, 2012
    Posts:
    27
    I don't understand. "properly terminate"
    Do you mean its not properly terminating. What's the solution? it's a .mp4 file. Possibly the compression of the file is not compatible with IOS?
     
    Last edited: Jul 9, 2012
  6. Diviner

    Diviner

    Joined:
    May 8, 2010
    Posts:
    677
    It's properly terminated, it's just not released. This is intentional on behalf of Apple, to maintain the functionality of replaying the movie without having to reload it. A movie is only released when a new movie is played, or when iOS starts shutting down running apps to release memory.

    There is no current work-around to completely clean up the memory from a movie played. There is however a "trick" to reduce the memory overhead.

    As soon as your movie stops playing, immediately load up a new movie, 1-2 seconds long without audio, with as low file size as possible.

    If done right, the second clean-up movie will replace the first and the original movie will be released. This is what we're doing for our current game and we're able to playback 30 minutes long cut-scenes during gameplay on iPhone3GS.
     
  7. DFiable

    DFiable

    Joined:
    Mar 3, 2012
    Posts:
    27
    Awesome! Thank you!
    That worked great! Problem solved.
     
    Last edited: Jul 9, 2012