-1

In my application, every time when the connect button is pressed a new dialog is created. The dialog may contain different items every time, because the items are collected from the system. That will generate many objects of that type. Is that a bad practice? Will the garbage collector take care of it? Should i optimize the code and how?

pairedDevicesDialog = new AlertDialog.Builder(context);

Thanks!

Ted Tedson
  • 316
  • 1
  • 6
  • 15
  • 1
    Instead of doing downvote, can we move move this question to appropriate exchange? He seems new on SO. Atleast tell him the reason for downvote. No worry he is not going to downvote your stuffs because he has not more points – Pankaj Kumar May 30 '14 at 13:02

1 Answers1

1

The Object will be garbage collected when there is nothing holding on to it, like any other Object. If you click the Button many times it will create many Objects and the garbage collector will have to do more work. It will all depend on how often you press the Button

Emmanuel
  • 13,083
  • 4
  • 39
  • 53