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 BigHandInSky · Feb 11, 2016 at 05:11 PM · texture2dkinectmemory-leak

Kinect SensorData Memory Leak

Hello all,

As in the title, I have a memory leak which I've had no luck in solving as of yet, it's something to do with this code:

 private IEnumerator KinectFeedHandler()
     {
         Debug.Log("KinectFeedHandler");
 
         while (!KinectManager.Instance)
         {
             Debug.Log("KinectColourFeed waiting for kinectmanager instance");
             yield return new WaitForEndOfFrame();
         }
         
         KinectInterop.SensorData currentData = KinectManager.Instance.GetSensorData();
         Renderer renderer = GetComponent<Renderer>();
         
         while (true)
         {
             yield return new WaitForEndOfFrame();
             
             Texture2D currentTexture2D = new Texture2D(currentData.colorImageWidth, currentData.colorImageHeight);
             currentTexture2D.SetPixels32(currentData.colorImageTexture.GetPixels32());
             currentTexture2D.Apply();
 
             renderer.material.mainTexture = currentTexture2D;
         }
     }

if I have my script not run this enumerator, then it will stay at a steady ~235MB (Value from Windows 10 Task manager), whereas running this, the memory usage will rise a steady 100MB every second or so - testing with a kinect this enumerator does work as expected (taking a color feed and transferring it onto a material every frame) but is producing this unexpected memory usage.

I've tested nullifying the texture2D directly after assigning it to the mainTexture, declaring the variable outside the while(true) scope, I'm ensuring and have checked that there is only one KinectFeedHandler enumerator running, and trying to check the sensor data colorImage before assignment has been fruitless too.

This is being tested in an empty scene save for a camera, Quad (+ this script), KinectManager which is only computing the Color Map, and is using the "Kinect v2 with MS-SDK" unitypackage, and the material the texture2D is being set onto is a base Unlit Texture.

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
Best Answer

Answer by BigHandInSky · Feb 11, 2016 at 05:28 PM

Found it through the help of this reddit post, turns out unity doesn't handle the disposal of new Texture2D's nicely, so to get a kinect's color feed use this:

     private IEnumerator KinectFeedHandler()
     {
         Debug.Log("KinectFeedHandler");
 
         while (!KinectManager.Instance)
         {
             Debug.Log("KinectColourFeed waiting for kinectmanager instance");
             yield return new WaitForEndOfFrame();
         }
         
         KinectInterop.SensorData currentData = KinectManager.Instance.GetSensorData();
         Renderer renderer = GetComponent<Renderer>();
         Texture2D currentTexture2D = new Texture2D(currentData.colorImageWidth, currentData.colorImageHeight);
 
         while (true)
         {
             yield return new WaitForEndOfFrame();
             
             currentTexture2D.SetPixels32(currentData.colorImageTexture.GetPixels32());
             currentTexture2D.Apply();
 
             renderer.material.mainTexture = currentTexture2D;
         }
     }
Comment
Add comment · 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

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

37 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

Related Questions

Memory Leak with creating a new Textrure2D 2 Answers

Dynamic face mesh from Kinect- applying a texture 0 Answers

cleanup allocated memory for texture2D 1 Answer

How to release memory of Texture2D dynamic object, or is there a memory-leak? 0 Answers

Loading external Image as Texture2D increases memory consumption dramatically on 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