Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by manny003 · Sep 26, 2014 at 10:54 AM · javascriptmemory leakscreencapture

Taking Screenshot Thumbnail causes memory spike that is not released

Do I have a memory leak here? I have a routine that runs at the top of each level to take a screenshot in JPG format and scale it down to a smaller thumbnail size to be used later in a saved game load routine. My problem is that when I monitor the memory usage in XCode, the memory spikes but does not come back down -- even after I do a System.GC or UnloadUnusedAssets -- just for good measure.

Below is the function in full (I include sections I've commented out to maybe shed light on my thinking):

 function takeBoardScreenShot() {
     var imageFilename : String = globalData.currSetInfo().setID + "_" + currentPlayer.currentBoard + ".jpg";
     
     var fileNameWithPath : String = Application.persistentDataPath + "/" + imageFilename;
     
     if (!File.Exists(fileNameWithPath)) {
         // FIX ME:  Find a way to take screenshot without background !!!
 
         var screenShotCam : Camera = Camera.main; 
         
         var resWidth = Screen.width;
         var resHeight = Screen.height;
 
         var rt : RenderTexture = new RenderTexture(resWidth, resHeight, 24);
         //screenShotCam.targetTexture = rt;
         var screenShot : Texture2D  = new Texture2D(resWidth, resHeight, TextureFormat.RGB24, false);
         RenderTexture.active = rt;
         screenShotCam.Render();
         
         yield new WaitForEndOfFrame();
         
         screenShot.ReadPixels(new Rect(0, 0, resWidth, resHeight), 0, 0);
         screenShotCam.targetTexture = null;
         RenderTexture.active = null; // JC: added to avoid errors
         Destroy(rt);

         // reduce image to one quarter size
         var absMinWidth : int = Screen.width / 4;
         
         if (screenShot.width > absMinWidth)
             TextureScale.Bilinear(screenShot, absMinWidth, (absMinWidth / parseFloat(Screen.width)) * Screen.height);
 
         //var bytes : byte[] = screenShot.EncodeToPNG();
         //System.IO.File.WriteAllBytes(fileNameWithPath, bytes);
 
         //System.IO.File.WriteAllBytes(fileNameWithPath, screenShot.EncodeToPNG());
         System.IO.File.WriteAllBytes(fileNameWithPath, screenShot.EncodeToJPG());
 
         Debug.Log(String.Format("Took screenshot to: {0}", fileNameWithPath));
         
         globalData.updateThumbPath(currentPlayer.currentBoard, imageFilename);
         
         //bytes = null;
         Destroy(screenShot);
     }
 
     levelState = EnumLevelState.eTakeThumbnailComplete;
 }


Some things worth mentioning, "globalData" is a DontDestroyOnLoad gameObject that has a function updateThumbPath to store the name and path of the screenshot in user prefs. It only writes the text file path name of the thumb image and not the mage itself so I don't think that's where my problem is. I tried the Profiler with the Trial Pro License but could not see anything.

Any tips?

Thanks, Manny

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

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

Assign Default For Large Array 1 Answer

Scripting Javascript 1 Answer

Change instance local variable through RPC to All and to one 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