If I was using the YUI to show a dialog which I might want to appear, say, five times in the course of a page, would it be better to:
A) Instantiate one, and then show and hide it several times? or
B) Instantiate a new one each time it’s to be displayed, then dispose of it?
First option seems like it’d be faster. Second option seems like it’d require fewer resources.
Thoughts?
If it were me, I would instantiate one and show it several times.
You’ll save more resources over time. The resources you’re talking about to hold a dialog in memory are small when you compare the resources it takes to create new ones on demand. You’re users will also notice a small performance gain (given the time to create on demand versus using one that is already available).