1

I think I'm implementing this button click incorrectly. Every time i click it 300KB of memory is taken up. If i keep clicking it, java's garbage collection will eventually clear SOME of the memory used, but not all of it.

Anybody have any idea what I'm missing?

  final Button lousbButton = (Button) findViewById(R.id.bButton);

    lousbButton.setOnClickListener(

            new Button.OnClickListener() {
                public void onClick(View v) {
                    TextView lousText = (TextView) findViewById(R.id.displayText);
                    if (lousText.length() < 15) {
                        lousText.setText(lousText.getText() + "B");
                        fontChange(lousText);


                    }
                }

            }

    );
user2338241
  • 7
  • 1
  • 2
  • 1
    This looks fine to me, although as a separate optimization you can move the `findViewById` call outside of the `clickListener` and declare it as `final`. You say that Java's GC will clear some of the memory, but after it clears and you keep pressing, after it clears a second time does it go back to the same amount as after the first clear? – RogueBaneling Jan 23 '16 at 16:39
  • @RogueBaneling Yes, it clears to around the same point as the first dump, but that level is still MB's higher than before any button clicks when the app first starts – user2338241 Jan 23 '16 at 16:43
  • Okay, so that indicates that it is still using the memory for something else which might not be as obvious. However, the fact that it clears the same amount each time indicates that it is not accumulating memory, and therefore there isn't a leak. Sounds like you have nothing to worry about. – RogueBaneling Jan 23 '16 at 16:45
  • [see this post about memory](http://stackoverflow.com/a/5682234/4101906) – Rahmat Waisi Jan 23 '16 at 17:09

0 Answers0