Button Click memory leak

0 Louis Sokol · January 24, 2016
Hi everyone, 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);
lousText.setText(lousText.getText() + "B");
fontChange(lousText);


}


}

);


Post a Reply

Replies

Oldest  Newest  Rating
0 Gary Whitney · January 24, 2016
1. Strings are immutable. If the textView contains a long string then every time you click you are creating a new long string.
2. fontChange is part of your onClick method. Maybe it is creating new objects i.e. more memory used.
  • 1

Java / Android Development

107,239 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator