In SWT usually dispose has to be executed, but in FWT examples there is no a dispose().
How FWT avoid to use dispose()?
Thank you in advance.
Mic
KevinKelleyTue 17 Jul 2012
It's handled (as much as possible anyway) in the java layer -- grep for dispose in fantom src/fwt/java dir finds 47 uses in 10 files... have a look there...
In gfx::Desktop there's dispose methods for disposeImage, ...Font, and ...Color, although I've never been clear on why Color would use resources. Font I think does some caching, so that there's no real issue with it.
As far as the SWT peers for FWT widgets: when the widget gets "mounted" its peer is created; when it gets removed the peer is disposed -- so you can't add an old, removed component back into the view, you must create a new widget object, which will have a new peer.
Mostly it all just works -- so much so that I had to think a while to remember, how. Creating Image resources is about the only time you need to think about dispose, similar to how you need to always remember to flush or close an OutStream.
((edit) actually that last sentence isn't right: usually you don't need to flush or close OutStreams, just, it's easier to always do it than explain when / when not / it's okay.)
brianTue 17 Jul 2012
Summary of the basic design (in SWT, not JS)...
The gfx classes are actually just data structures designed to be used outside of any specific toolkit. For example Image is just a wrapper around a Uri and Font is just a data structure with name, size, styling.
When you use Font, Color, Brush, Image, etc in the context of a FWT operation then it gets mapped to a SWT resource. Pretty much everything is cached so that 1000 images all with the same Uri will get mapped to the same actual SWT image.
You can manually dispose of these underlying representations using Image.dispose, Font.dispose, etc. (These methods deprecated the old Desktop dispose methods).
But in general due to the caching design, colors, fonts, etc don't really matter. The only thing you should dispose is Images you are loading manually or creating. Icons are usually best left in cache.
Mic Mon 16 Jul 2012
Hello,
In SWT usually dispose has to be executed, but in FWT examples there is no a dispose().
How FWT avoid to use dispose()?
Thank you in advance.
Mic
KevinKelley Tue 17 Jul 2012
It's handled (as much as possible anyway) in the java layer -- grep for
dispose
in fantom src/fwt/java dir finds 47 uses in 10 files... have a look there...In
gfx::Desktop
there's dispose methods fordisposeImage
,...Font
, and...Color
, although I've never been clear on whyColor
would use resources.Font
I think does some caching, so that there's no real issue with it.As far as the SWT peers for FWT widgets: when the widget gets "mounted" its peer is created; when it gets
remove
d the peer is disposed -- so you can't add an old,remove
d component back into the view, you must create a new widget object, which will have a new peer.Mostly it all just works -- so much so that I had to think a while to remember, how. Creating Image resources is about the only time you need to think about dispose, similar to how you need to always remember to
flush
orclose
anOutStream
.((edit) actually that last sentence isn't right: usually you don't need to flush or close OutStreams, just, it's easier to always do it than explain when / when not / it's okay.)
brian Tue 17 Jul 2012
Summary of the basic design (in SWT, not JS)...
The gfx classes are actually just data structures designed to be used outside of any specific toolkit. For example Image is just a wrapper around a Uri and Font is just a data structure with name, size, styling.
When you use Font, Color, Brush, Image, etc in the context of a FWT operation then it gets mapped to a SWT resource. Pretty much everything is cached so that 1000 images all with the same Uri will get mapped to the same actual SWT image.
You can manually dispose of these underlying representations using Image.dispose, Font.dispose, etc. (These methods deprecated the old Desktop dispose methods).
But in general due to the caching design, colors, fonts, etc don't really matter. The only thing you should dispose is Images you are loading manually or creating. Icons are usually best left in cache.