Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Need I destroy the image created for a draw2d figure?and Where?
Need I destroy the image created for a draw2d figure?and Where? [message #237193] Wed, 25 July 2007 09:01 Go to next message
David BY Chan is currently offline David BY ChanFriend
Messages: 40
Registered: July 2009
Member
here I wrote a *EditPart* and overrode the method *createFigure* like
this below:

protected void createFigure()
{
String file_path = ...
Image img = new Image(null,file_path);
ImageFigure image_figure = new ImageFigure(img);
image_figure.setOpaque(true);
return image_figure;
}

As you know, image is OS-dependent resource, it doesn't destroy except
explicitly release, but I didn't found the *dispose* method in IFigure
or EditPart.

Thanks a lot!
Re: Need I destroy the image created for a draw2d figure?and Where? [message #237290 is a reply to message #237193] Sat, 28 July 2007 21:56 Go to previous messageGo to next message
Alex Boyko is currently offline Alex BoykoFriend
Messages: 200
Registered: July 2009
Senior Member
Hi,

There is an editpart associated with a figure, hence you can dispose your
image in #deacivate method of the editpart. Since, usually image is cached
on the figure, if image gets updated you need to dispose the old one
before creating creating the new one.
Hope this helps.

Cheers,
Alex
Re: Need I destroy the image created for a draw2d figure?and Where? [message #237314 is a reply to message #237290] Mon, 30 July 2007 09:43 Go to previous message
David BY Chan is currently offline David BY ChanFriend
Messages: 40
Registered: July 2009
Member
Alex Boyko wrote:
> Hi,
>
> There is an editpart associated with a figure, hence you can dispose
> your image in #deacivate method of the editpart. Since, usually image is
> cached on the figure, if image gets updated you need to dispose the old
> one before creating creating the new one.
> Hope this helps.
>
> Cheers,
> Alex
>
Thanks you Alex, I selected the most foolish way to solve this problem,
that is, to create a help class ResourceManager to manage some resource
that can't be collected by GC for EditorPart, which includes the method
dispose.

The class ResourceManager is used to cache the resource needed by Figure
such as image, font and color, it also contains a method dispose to
destroy any resource when the EditorPart's method 'dispose' be invoked.

If I put the Create-Destroy process in the methods 'activate' and
'deactivate', there are two disadvantages:

1. Create-Destroy is a little more frequent, need more CPU calculations

2. Can't be reused if two figures need the same image or resource.

Thanks again!
Previous Topic:Is there a Way to draw a Polygon with a curved line on one side?
Next Topic:TextEditor into new tab
Goto Forum:
  


Current Time: Wed Apr 24 23:11:55 GMT 2024

Powered by FUDForum. Page generated in 0.03514 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top