Is usage of cardlayout memory efficient? For example if i load 20 JPanel’s into cardlayout, it would probably occupy a lot of memory space. Would it be better to load few panels and later load some more and unload panels that won’t be used any more?
Share
A
CardLayoutwill indeed keep strong references to allComponents which are added to it. So yes, from a memory point of view it would be better to removeComponents again if you won’t need them anymore.Probably about as efficient as any other layout. The only difference is that you only see 1 panel at the same time when using a
CardLayout. Butting adding 20 panels to aCardLayoutwill more or less use the same amount of memory as adding them to aFlowLayout