Top Description Inners Fields Constructors Methods
org.eclipse.swt.graphics

public abstract Class Resource

extends Object
Class Inheritance
Known Direct Subclasses
org.eclipse.swt.graphics.TextLayout, org.eclipse.swt.graphics.Transform, org.eclipse.swt.graphics.Color, org.eclipse.swt.graphics.Cursor, org.eclipse.swt.graphics.Font, org.eclipse.swt.graphics.GC, org.eclipse.swt.graphics.Image, org.eclipse.swt.graphics.Path, org.eclipse.swt.graphics.Pattern, org.eclipse.swt.graphics.Region
Imports
java.util.function.*, org.eclipse.swt.*

This class is the abstract superclass of all graphics resource objects. Resources created by the application must be disposed.

Important Note

This class is intended to be subclassed only within the SWT implementation. However, it has not been marked final to allow those outside of the SWT development team to implement patched versions of the class in order to get around specific limitations in advance of when those limitations can be addressed by the team. Any class built using subclassing to access the internals of this class will likely fail to compile or run between releases and may be strongly platform specific. Subclassing should not be attempted without an intimate and detailed understanding of the workings of the hierarchy. No support is provided for user-written classes which are implemented as subclasses of this class.

Since
3.1
See Also
dispose, isDisposed, Sample code and further information

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
Resource.ResourceTracker

Used to track not disposed SWT resource.

Field Summary

Modifier and TypeField and Description
pack-priv Device
device

the device where this resource was created

private static Consumer<Error>
nonDisposedReporter

Used to report not disposed SWT resources, null by default

private Resource.ResourceTracker
tracker

Used to track not disposed SWT resource

Constructor Summary

AccessConstructor and Description
public
pack-priv
Resource(Device device)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
public void
dispose()

Disposes of the operating system resources associated with this resource.

public Device

Returns:

Device the device of the receiver
getDevice
()

Returns the Device where this resource was created.

pack-priv void
pack-priv void
init()

pack-priv void
public abstract boolean

Returns:

true when the resource is disposed and false otherwise
isDisposed
()

Returns true if the resource has been disposed, and false otherwise.

public static void
setNonDisposeHandler(Consumer<Error>
object used to report detected errors. Use null to disable tracking. Setting a new reporter has an immediate effect.
reporter
)

Enables detection of Resource objects for which dispose() wasn't called, which means a leak of native memory and/or OS resources.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

deviceback to summary
pack-priv Device device

the device where this resource was created

nonDisposedReporterback to summary
private static Consumer<Error> nonDisposedReporter

Used to report not disposed SWT resources, null by default

trackerback to summary
private Resource.ResourceTracker tracker

Used to track not disposed SWT resource

Constructor Detail

Resourceback to summary
public Resource()
Resourceback to summary
pack-priv Resource(Device device)

Method Detail

destroyback to summary
pack-priv void destroy()
disposeback to summary
public void dispose()

Disposes of the operating system resources associated with this resource. Applications must dispose of all resources which they allocate. This method does nothing if the resource is already disposed.

getDeviceback to summary
public Device getDevice()

Returns the Device where this resource was created.

Returns:Device

Device the device of the receiver

Since
3.2
ignoreNonDisposedback to summary
pack-priv void ignoreNonDisposed()
initback to summary
pack-priv void init()
initNonDisposeTrackingback to summary
pack-priv void initNonDisposeTracking()
isDisposedback to summary
public abstract boolean isDisposed()

Returns true if the resource has been disposed, and false otherwise.

This method gets the dispose state for the resource. When a resource has been disposed, it is an error to invoke any other method (except dispose()) using the resource.

Returns:boolean

true when the resource is disposed and false otherwise

setNonDisposeHandlerback to summary
public static void setNonDisposeHandler(Consumer<Error> reporter)

Enables detection of Resource objects for which dispose() wasn't called, which means a leak of native memory and/or OS resources.

Warning

the reporter will be called from a different thread. Do not block it and do not throw any exceptions. It's best to queue the errors for some other worker to process.

Parameters
reporter:Consumer<Error>

object used to report detected errors. Use null to disable tracking. Setting a new reporter has an immediate effect.

Since
3.116
org.eclipse.swt.graphics back to summary

private Class Resource.ResourceTracker

extends Object
Class Inheritance

Used to track not disposed SWT resource. A separate class allows not to have the finalize when tracking is disabled, avoiding possible performance issues in GC.

Field Summary

Modifier and TypeField and Description
private Error
allocationStack

Recorded at Resource creation if setNonDisposeHandler was enabled, used to track resource disposal

pack-priv boolean
ignoreMe

Allows to ignore specific Resources even if they are not disposed properly, used for example for Fonts that SWT doesn't own.

private Resource
resource

Resource that is tracked here

Constructor Summary

AccessConstructor and Description
pack-priv
ResourceTracker(Resource resource, Error allocationStack)

Method Summary

Modifier and TypeMethod and Description
protected void
finalize()

Overrides java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
Inherited from java.lang.Object:
cloneequalsgetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allocationStackback to summary
private Error allocationStack

Recorded at Resource creation if setNonDisposeHandler was enabled, used to track resource disposal

ignoreMeback to summary
pack-priv boolean ignoreMe

Allows to ignore specific Resources even if they are not disposed properly, used for example for Fonts that SWT doesn't own.

resourceback to summary
private Resource resource

Resource that is tracked here

Constructor Detail

ResourceTrackerback to summary
pack-priv ResourceTracker(Resource resource, Error allocationStack)

Method Detail

finalizeback to summary
protected void finalize()

Overrides java.lang.Object.finalize.

Doc from java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.

When running in a Java virtual machine in which finalization has been disabled or removed, the garbage collector will never call finalize(). In a Java virtual machine in which finalization is enabled, the garbage collector might call finalize only after an indefinite delay.

The general contract of finalize is that it is invoked if and when the Java virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize method may take any action, including making this object available again to other threads; the usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.

The finalize method of class Object performs no special action; it simply returns normally. Subclasses of Object may override this definition.

The Java programming language does not guarantee which thread will invoke the finalize method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.

After the finalize method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.

The finalize method is never invoked more than once by a Java virtual machine for any given object.

Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored.

Annotations
@Override