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
2
Question by doug__ · Jan 24, 2013 at 05:30 AM · texture2d

How do you free a manually created texture?

This is probably trivial, but I'm loading a very very large texture like this:

   // Load huge tga map as an image.
   var i = new nImage();
   i.Load("map.tga");
 
   // Create texture from subsection of image
   Texture t = i.Texture(640, 640, 1200, 1200);

Afterwards I want to dispose of the texture I've created. Normally if I loaded a texture using Resources.Load() I'd use Resources.UnloadAsset() to dispose of it.

However, this texture is created using (internally to nImage):

     public Texture2D Texture (int x, int y, int width, int height)
     {
       var bytes = Section (x, y, width, height);
       if (bytes == null)
         return null;
       var texture = new Texture2D(width, height, TextureFormat.ARGB32, true, true);
       texture.SetPixels32(bytes, 0);
       texture.Apply();
       return texture;
     }

How do I force the texture to be removed from the graphics memory of the card?

(It doesn't appear to be automatic, because I'm hitting memory exhaustion errors on the graphics card after a while).

Comment
Add comment · Show 1
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 sdgd · Jan 24, 2013 at 06:03 AM 0
Share

am force remove texture well restarting system does that as all memory(RA$$anonymous$$) is erased

while the HDD stuff remains

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by ryba · Jan 24, 2013 at 06:06 AM

You dont free anything manually in C#. Memory is managed by mechanism called Garbage Collector, it releases memory at its own time, you can however make a request for garbage collector to start collecting unused memory by calling GC.Collect(); But be aware it doesnt clean up memory, only informs garbage collector that you want him to collect mem. You can also use GC.WaitForPendingFinalizers() method, that will perform similiar to GC.Collect(), but also it will freeze your application untill cleanup is performed, so its most like direct cleanup method, but not exactly, also keep on mind that calling WaitForPendingFinalizers(), especially while game is running, is rather bad idea, since it can freeze your app badly.

You can read more about it here http://docs.unity3d.com/Documentation/Manual/UnderstandingAutomaticMemoryManagement.html

About Resources.UnloadAssets() - i dont know what does it exatly do but i assume it closes opened IO resources, like file descriptors, rather then really free memory (however its releated).

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 doug__ · Jan 24, 2013 at 07:35 AM 0
Share

The issue is that the graphics memory seems to be used by creating Texture2D objects, but never released.

avatar image
0

Answer by madc9ke · Oct 23, 2017 at 12:20 PM

I just stumbled upon this problem when working on my dual quaternion skinning script.

I use textures to pass data to GPU for calculations and retrieve results.

After optimizing everything else the biggest bottleneck is GC.Collect() when using GetPixels (code below)

https://bitbucket.org/MadC9ke/unity3d-dual-quaternion-skinning/src/a6ea850456861672faae59848e32dee1903decec/Code/DQ%20animator/MadCakeMeshAnimator.cs?at=master&fileviewer=file-view-default#MadCakeMeshAnimator.cs-192

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
avatar image
0

Answer by sonnyb · Dec 23, 2021 at 04:32 PM

I think you need to call Destroy on the manually created texture.

E.g. see Issue with Texture2D memory leak in Unity

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

14 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

Related Questions

Cast Texture2d to Sprite 4 Answers

Struggling to find how to access the Texture 2D of a sprite. 1 Answer

LoadImageIntoTexture function on webplayer 0 Answers

How do I access a texture slice's rect via scripting? 1 Answer

Unity3D error: Assets/Scripts/Item.cs(25,38): error CS0308: The non-generic method `UnityEngine.Resources.Load(string)' cannot be used with the type arguments 1 Answer


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