Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6351549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:01:48+00:00 2026-05-24T22:01:48+00:00

I wonder if this piece of code will cause memory leakage? because I still

  • 0

I wonder if this piece of code will cause memory leakage? because I still don’t know when is a texture should be disposed. should the texture disposed in the end of method? or dispose it separately after unused?

private void loadAssets() {
    Texture texture = new Texture(Gdx.files.internal("data/controls.png"));
    TextureRegion[] buttons = TextureRegion.split(texture, 64, 64)[0];
    left = buttons[0];
    right = buttons[1];
    jump = buttons[2];
    cubeControl = buttons[3];
    cubeFollow =  TextureRegion.split(texture, 64, 64)[1][2];
    dpad = new TextureRegion(texture, 0, 64, 128, 128);     
    batch = new SpriteBatch();
    batch.getProjectionMatrix().setToOrtho2D(0, 0, 480, 320);
}

and I don’t really understand. why does there’s still memory leakage in Java?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T22:01:49+00:00Added an answer on May 24, 2026 at 10:01 pm

    Looking at the source of TextureRegion, it retains a reference to the Texture but doesn’t really take “ownership” of it – it’s never going to dispose it itself.

    Going by that, you shouldn’t dispose of it at the end of the method, but you should dispose of it when cubeFollow, cubeControl and dpad are both finished with – which I suspect will be when the instance itself is finished with. (That may or may not mean you need a finalizer – it depends whether you have some control over the lifetime of this object.)

    Note that you don’t need a separate field to store a reference to the Texture – you can get it from dpad using dpad.getTexture().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wonder if I am missing some piece of code in this example.I am
I stumbled upon this piece of code while reading about DES encryption. I wonder
I wonder if this affects performance or memory consumption a lot. I need an
I have this piece of code in C: int q = 10; int s
I'm trying to write a xml schema that will validate this piece of xml:
I'v got this piece of code : CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB(); CGFloat colors[] =
In the reCaptcha script you'll find this piece of code: $recaptcha_response->is_valid = false; I
I have this little piece of code: <script> $(window).bind('beforeunload', function() { $.ajax({ async: false,
I just wrote this piece of code to represent this error that is killing
This is a piece of code I've written for a homework. It seems to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.