cancel
Showing results for 
Search instead for 
Did you mean: 

Difference between object.setVisible(false) and remove(object)

Tuoman
Senior II

If user wants to make object invisible, which method is the most efficient, e.g. in terms of performance or memory usage?

Generally, in which cases should use setVisible true/false vs. add/remove?

Is it so that the only difference is that remove/add modifies drawing order, but otherwise they are equal? (I.e. performance to draw removed or invisible objects are both neglible)

In that case add/remove should only be called in init (or if drawing order must be changed), and setVisible afterwards...

1 REPLY 1
qq3g7bad
Associate III

Hello, Tuoman.

> Is it so that the only difference is that remove/add modifies drawing order, but otherwise they are equal? 

No. It differs in several points. I will write my understanding.

`setVisible()` is a function to show a instance based on `Drawable` class.

  •  There are no effect to memory usage because `setVisible()` work on only its visibility.

`remove()` is a function to delete a instance based on `Drawable` class for future rendering.

  •  `remove()` is not a function of `Drawable` but of `Container` (Screen class has its own "root container". See here). 
  •  If a instance based on `Drawable` is removed from `Container`, it result in being removed from memory.
  •  When a user call `add()` for redrawing some widgets, TouchGFX might be acquire a new memory region for those widgets.

So I think as follows.

  • If you switch visibility of a component repeatedly, it is good to use `setVisible()`.
  • If you delete some instance and never use it, it is good to use `remove()`.