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

  • Home
  • SEARCH
  • 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 4063692
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:45:32+00:00 2026-05-20T15:45:32+00:00

My application is running out of memory which switching between two activities. The first

  • 0

My application is running out of memory which switching between two activities. The first activity is running an OpenGL scene, the second activity is not. I want to make sure I am releasing all of the textures used by the OpenGL scene.

Right now I am using this method

getNativeHeapAllocatedSize()

to track the relative amount of memory used by the textures. This number goes up by about 4 megs if I allocate textures. However it never seems to go back down again.

In my first activities ‘OnPause’ I have the following code:

SurfaceView.onPause();
mTexture = null;

In the second activity I then call getNativeHeapAllocatedSize() several times. Even after the GC has run and the memory still has not dropped.

Edit:

After more research it appears it is something with the code that loads the data. I have removed OpenGL from the equation and the memory is still not being released.

try {
        InputStream is = null;
        {
            AssetManager am = MyActivity.getAssetMgr();
            is = am.open( fileName );
        }

        Bitmap b = BitmapFactory.decodeStream( is );
        if( b != null ) {
            mResX = b.getWidth();
            mResY = b.getHeight();
            Bitmap.Config bc = b.getConfig();
            if( bc == Bitmap.Config.ARGB_8888 )
                mBPP = 4;
            else
                mBPP = 2;

            mImageData = ByteBuffer.allocateDirect( mResX * mResY * mBPP );
            mImageData.order( ByteOrder.nativeOrder() );
            b.copyPixelsToBuffer( mImageData );
            mImageData.position( 0 );


            return true;
        }
    } catch (IOException e) {       
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }       
    return false;
}

Edit2:

I did end up adding in all your ideas. However this seemed to be the problem in my case…

ByteBuffer not releasing memory

  • 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-20T15:45:33+00:00Added an answer on May 20, 2026 at 3:45 pm

    I am assuming you mean textures loaded to GPU via gl.glTexImage* or any other helper method. In that case GC wont help you, it is not cleaning internal memory used by textures

    Have you tried manually deleting your textures via gl.glDeleteTextures?

    Edit according to new code:

    Several leaks in your code:

    • close the input stream
    • recycle your bitmap after you have copied data to ByteBuffer
    • I guess you use the byteBuffer with image data to upload texture to GPU, make sure you do not store references to those buffers after data was uploaded.

    I do not see any other problems in the this code, if after this fixes it still wont work, than look close at any bitmap usages in your app.

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

Sidebar

Related Questions

I have a rails application running on a Linux server. I would like to
I have an application running in tomcat that has a bunch of configuration files
I have a web application running on a Gentoo-based LAMP stack. My customers buy
I have a windows application running at the backend. I have functions in this
I have an application running only on Windows and a batch file that launches
I have an application running on multiple IIS servers that need to parse a
For my web application running on LAMP, I need to be able to deploy
I have a Swing Application running under Linux, that has problems to display accented
I have a distributed Java application running on 5 application servers. The servers all
We have an ASP.NET application running at a customer site that uses ActiveDirectory for

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.