Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 ling_yeo · 5 days ago · memory managementcaching

(ROS) App crashes due to memory allocated

Hi everyone,

I'm new to Unity, and I'm currently using the Unity and ROS# to design and program my UI to communicate with the ROS machine.


I'm able to publish and subscribe to data such as sensor data and compressed image data in my UI. But when I hold my UI on the same page for around 10 to 15 mins, my app will crash automatically. At the same time, I can find my memory was being accumulated more than 10GB in the System Monitor on the Ubuntu system.


I tried searching online and find this Caching.ClearCache()in Unity API to clear the application's cache. And added this in my void FixedUpdate()


May I know am I on the right way to try to solve this kind of problem? or which way should think about it.


Thank you so much.

Comment
Add comment · Show 2
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 andrew-lukasik · 5 days ago 1
Share

I tried searching online and find this Caching.ClearCache()in Unity API to clear the application's cache

To release memory allocated by anything that inherits from UnityEngine.Object call UnityEngine.Object.Destroy( thatObject );
avatar image ling_yeo andrew-lukasik · 5 days ago 0
Share

Hi Andrew,

Thank you for sharing. Please let me try this method on my code.

And I really appreciated your advice.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by andrew-lukasik · 5 days ago

(...) compressed image data (...)

  1. Are you creating new image every time the data changes?

  2. Are you releasing or reusing that image?

If the answer to the question #1 is "yes" and #2 is "no" - here is the reason for app crashing. Release or reuse.

Comment
Add comment · Show 4 · 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 ling_yeo · 5 days ago 0
Share

Hi Andrew, Thank you for your answer. I was using the following function to display video in my UI:

 private void ProcessCameraPaintImage(byte[] a_data)
         {
             if(a_data != null)
             {
                 Texture2D t_texture2D = new Texture2D(1,1);;
                 t_texture2D.LoadImage(a_data);
                 m_campaint_rawimage.texture = t_texture2D;
                 m_campaint_rawimage.color = Color.white;
             }
         }

and I'm not very sure I'm creating a new image every time.

avatar image andrew-lukasik ling_yeo · 4 days ago 1
Share


new Texture2D(1,1); allocates a small buffer and then t_texture2D.LoadImage(a_data); allocates a buffer size of a_data.Length bytes. I see no code related to releasing the memory that was allocated in the previous ProcessCameraPaintImage call - which is precisely what you need to do here to fix this memory leak.


try this:

 void ProcessCameraPaintImage(byte[] a_data)
 {
     if(a_data != null)
     {
         if( m_campaint_rawimage.texture!=null )
             Destroy( m_campaint_rawimage.texture );
         
         var tex = new Texture2D(1,1);;
         tex.LoadImage(a_data);
 
         m_campaint_rawimage.texture = tex;
         m_campaint_rawimage.color = Color.white;
     }
 }


avatar image ling_yeo andrew-lukasik · 4 days ago 0
Share

Hi Andrew,

Thank you for your reply and explanation of my question.

I will try it now. Again, thank you so much!!

Show more comments

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

186 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 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 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

[UNet] Best practice to cache components in NetworkBehaviour 0 Answers

Playable Loading Screen, does it make sense? Advanced loading screen 2 Answers

Mystery memory consumption on iPhone 5s iOS8 vs iPod 5 ios7 0 Answers

Game crashes on start due to large gameObject 0 Answers

no way to build games in low memory in unity? 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