How to do correct memory management in the app?

Hello) I have a project with this concept:
media photos and videos are located in the scene on the objects in world coordinates(there are pre-created) image - spriterenderer, video video player component
the problem arises when I create more than one large video in the scene, the application crashes. videos and images now lie in a regular folder in the project. I did not pre-load on the stage, and just have links to content in gamobject.
how to do it properly so as not flying?
June 3rd 19 at 21:03
1 answer
June 3rd 19 at 21:05
If the scene has any references to objects outside of the scene, when the scene loads they all fit into memory. Resources won't do you much help, they just kill you application. You need to stream videos directly from disk, for example, from the StreamingAssets folder. The details are in the documentation.
but I don't have that much opportunity to put a video in the streamingassets, and then suddenly the user will break your app until there will be music cast(( how then to be? - modesto43 commented on June 3rd 19 at 21:08
That means break? Even if the user somehow gets to this folder, and something to put, how can anything break? You that everything are collected in the video player to load? - litzy commented on June 3rd 19 at 21:11
no suddenly it the video will be removed or renamed, then it will become invisible. therefore to handle this situation. and an inexperienced user will cry if you break something yourself)))
so I still try to use the resources.
loaded asynchronously, use-done, removed the references and stupidly unloaded after use, but this has not led to the expected result. the program already crashes in the beginning, but only when trying to load the resource. the fact that I have three resources at 500 MB, not small files. maybe there is still subtlety? after all, once the file in 500MB when I hit the compile not resurses, it pulled it. but two and three are not pulling off at startup.
heard that you need at program start "demand" a lot more, so that such trouble was not. heard of it? but heaps of different small and large and how to influence them? - modesto43 commented on June 3rd 19 at 21:14
in General it takes about a Gigabyte big pile. that fits music podcast on pause and live in MB 500...
what you need to know? - modesto43 commented on June 3rd 19 at 21:17
, StreaminAssets is a system folder, it's not even on all platforms it is possible standard means to get there. And then you can pieces of application to remove, then also all fails, you such scenario is also processing going? - litzy commented on June 3rd 19 at 21:20
come on now with these StreamingAssets. Better tell me what I lack in resources.
I stopped on the fact that objects fall more than 80MB in a heap for large objects where it is not possible to defragment. but to cram more in there couldn't through resurses - modesto43 commented on June 3rd 19 at 21:23
,
this coroutine starts when you first access the player object
IEnumerator VideoPlayerUpd()
{
 ThisBind Bind = new Bind(this.gameObject, binded);
 player.GetComponent<dragcontroller>().SetBind(ref thisBind);
 float time = 0f;
 yield return null;
 An asyncrequest ResourceRequest = Resources.LoadAsync(clipName, typeof(VideoClip));
//anim
 while (!an asyncrequest.isDone || time < 1f)
{
 time += 0.05 f;
 time = Mathf.Clamp01(time);
 seek.value = an asyncrequest.progress * time;
 yield return new WaitForSeconds(0.05 f);
}
 movie = (VideoClip)an asyncrequest.asset;
 vp.clip = movie;
 an asyncrequest = null;
//anim
//setsource
 vp.SetTargetAudioSource(0, source);
 vplayersta = VPlayerState.binded;
 time = 0f;
 while (true) 
{
 binded = thisBind.res;
 if (!binded)
Unbinded();
 if (vp.isPlaying) 
{
//
 yield return new WaitForSeconds(0.1 f);
 } 
 else 
{
//
 yield return new WaitForSeconds(0.25 f);
}
}
 }</dragcontroller>

and this code execute when you cease to use it after coroutine stopped
private void UnloadResource()
{
 movie = null;
 vp.clip = null;
Resources.UnloadUnusedAssets();
 }
- modesto43 commented on June 3rd 19 at 21:26
May on the clip still have the Destroy call, see Profiler. - litzy commented on June 3rd 19 at 21:29
,
now video loading for half an hour of the resources, and think more time need a URL to use
Resources.UnloadUnusedAssets(); removes the data from memory without reference to now, why even destroy? - modesto43 commented on June 3rd 19 at 21:32

Find more questions by tags Unity Game Engine