
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
45 lines
1.1 KiB
Plaintext
45 lines
1.1 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Java's garbage collection cannot be relied on to clean up everything. Specifically, subclasses of ``++org.eclipse.swt.graphics.Resource++`` must be manually ``++dispose()++``-ed when you're done with them.
|
|
|
|
Particularly for the ``++Image++`` subclass, which retains an open ``++FileHandle++`` for the life of the instance, failure to properly ``++dispose++`` of ``++Resource++``s can result in a resource leak which could bring first the application and then perhaps the box it's on to their knees.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,java]
|
|
----
|
|
import org.eclipse.swt.graphics.Image;
|
|
|
|
public class MyLeakyView {
|
|
Image myImage = new Image("image/path"); // Noncompliant; not disposed
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,java]
|
|
----
|
|
import org.eclipse.swt.graphics.Image;
|
|
|
|
public class MyView {
|
|
Image myImage = new Image("image/path");
|
|
|
|
public void callMeWhenItsDone() {
|
|
myImage.dispose();
|
|
}
|
|
----
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Add a "dispose" method call for this "xxx"
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|