... | ... | @@ -203,3 +203,19 @@ At some time during our process, we need to calculate the complete height of the |
|
|
|
|
|
The maximum width can only be calculated in pixel, since the other metric (character) is not reliable between different fonts.
|
|
|
|
|
|
## Cleaning up everything once the widget is no longer used
|
|
|
|
|
|
Coding SWT is a little bit inconvenient for a java developer. Why? Well, SWT creates its widgets similar to the underlying Operating System(OS) This is a cool feature, because once the OS changes our application will immediately adapt its styling as well! But here comes the down fall - Every resource we use is given by the OS (Resources are Fonts,Colors,Images, etc...) which means the OS allocates memory for us. If we do not notify the OS that we do no longer need the resource, that memory is lost for the entiretiy of out applications life time! And at some point, the OS wont let us reserve any more of a given resource because either there is no more ram or there aren any left!
|
|
|
This is why whenever you create such a resource you are responsible of disposing it accordingly. Let me give you an example of a code that does not work!
|
|
|
|
|
|
```java
|
|
|
Color colorWhite=null;
|
|
|
|
|
|
int i=100;
|
|
|
while(i>0){
|
|
|
colorWhite = new Color(Display.getCurrent(), new RGBA(255, 255, 255, 0));
|
|
|
i--;
|
|
|
}
|
|
|
|
|
|
```
|
|
|
|