Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by link1375 · Nov 26, 2017 at 12:05 PM · arraytexture2dwebcamtextureramout of memory

Save Webcamtextures. Why running out of memory (ram)?

I know this is not a nice code but I need help with the overall problem that I am running out of memory (same happens if I use a LinkedList). What the code does is, that I save a picture around every 40ms till I have 1000 texture2Ds in an array and then start overwriting from the begin. But is seems that the overwritten textures are not deleted from the memory although they are out of scope.

     public RawImage display;
     public AspectRatioFitter imageFitter;
 
     public static Texture2D[] picArray;
     public static WebCamTexture webCamTex;
     public static int numberSavedPics = 1000;
     public static int counter = 0;
 
     private int firstPic = 0;
     private int lastPic = -1;
 
     void Start () {
         picArray = new Texture2D[numberSavedPics];
         WebCamDevice cam = WebCamTexture.devices [0];
         webCamTex = new WebCamTexture (cam.name);
         if (display != null) {
             display.texture = webCamTex;
             imageFitter = display.gameObject.GetComponent<AspectRatioFitter> ();
         }
         webCamTex.Play ();
     }
     
     // Update is called once per frame
     void FixedUpdate () {
         if (display != null) {
             float videoRatio = (float)StartScript.webCamTex.width/(float)StartScript.webCamTex.height;
             imageFitter.aspectRatio = videoRatio;
         }
 
         if (counter < numberSavedPics) {
             counter++;
         } else {
             deletePic ();
         }
 
         savePic ();
     }
 
     private void savePic(){
         Texture2D snap = new Texture2D (webCamTex.width, webCamTex.height);
         snap.SetPixels (webCamTex.GetPixels ());
         snap.Apply ();
         lastPic = ((lastPic + 1) % numberSavedPics);
         picArray [lastPic] = snap;
 
     }
 
     private void deletePic(){
         firstPic = ((firstPic + 1) % numberSavedPics);
     }
 
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Nov 26, 2017 at 04:21 PM

Any object that is derived from UnityEngine.Object has to be manually Destroy ed. This holds true for any such object which includes GameObjects, Meshes, Textures, ... Of course assets which are shipped with your application should not be destroyed (though it's possible).


Any UnityEngine.Object derived object in memory can be found again by using FindObjectsOfType. Those objects are "tracked" objects which actually live on the C++ side of Unity. Those objects have a managed part (which exists in the managed memory of the Mono framework) and a native part which lives in unmanaged memory of the engine.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image link1375 · Nov 26, 2017 at 07:05 PM 0
Share

Hey, thank you for your answer. But it is not all clear for me. I added the line`Destroy(picArray[firstpic])` to the deletePic() function but the memory usage still increases. I intend to map these textures from the array onto a rawimage every 40ms from an other script. Thats why the array is static. Do I have to destroy the rawimage.texture as well?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

87 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Out of memory(Max Size) 2 Answers

how do i get differences between a background and webcam texture like a green screen? 2 Answers

Texture 2D Arrays in Parallax Occlusion Mapping 0 Answers

Check if no webcam 0 Answers

Texture 2D array to GUI.Window rows iOS 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges