Update athen introduction to the texteditor authored by Markus Krug's avatar Markus Krug
...@@ -219,7 +219,7 @@ This is why whenever you create such a resource you are responsible of disposing ...@@ -219,7 +219,7 @@ This is why whenever you create such a resource you are responsible of disposing
``` ```
For a java developer it seems that we always reuse our color variable, however **ALWAYS, WHENEVER* we create an object with ```new``` the OS reserves the memory space! So make sure to always call ```dispose()``` on system resources before allocating a new one! For a java developer it seems that we always reuse our color variable, however **ALWAYS, WHENEVER** we create an object with ```new``` the OS reserves the memory space! So make sure to always call ```dispose()``` on system resources before allocating a new one!
```java ```java
Color colorWhite = null; Color colorWhite = null;
...@@ -235,3 +235,16 @@ For a java developer it seems that we always reuse our color variable, however * ...@@ -235,3 +235,16 @@ For a java developer it seems that we always reuse our color variable, however *
} }
``` ```
Coming back to our initial problem, keeping in mind what we just learned, we need a way to get rid of our remaining resources, once the widget gets destroyed. For this purpose we register a dispose listener.
```java
// add a dispose listener
this.addDisposeListener((DisposeEvent e) -> {
// dispose the color of the selection
colorSelection.dispose();
});
```
During this view we store a color that we use to display the selection of text, this handler assures that this resource is not lost!
To be continued...
\ No newline at end of file