Bug 148402 - [GMFGraph] Generated code should not create unlimited number of SWT Font and Color instances
Summary: [GMFGraph] Generated code should not create unlimited number of SWT Font and ...
Status: NEW
Alias: None
Product: GMF-Tooling (ARCHIVED)
Classification: Modeling
Component: Core (show other bugs)
Version: 1.0   Edit
Hardware: All All
: P2 normal (vote)
Target Milestone: 2.3   Edit
Assignee: Artem Tikhomirov CLA
QA Contact:
URL:
Whiteboard: Usability
Keywords: contributed
: 155983 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-06-23 11:34 EDT by Michael Golubev CLA
Modified: 2010-12-09 22:35 EST (History)
2 users (show)

See Also:


Attachments
Fixes the subj (97.84 KB, patch)
2006-06-23 11:56 EDT, Michael Golubev CLA
no flags Details | Diff
Fixes the subj (alternative way) (63.80 KB, patch)
2006-06-26 11:37 EDT, Michael Golubev CLA
no flags Details | Diff
Suggested patch for XPand templates (1.97 KB, patch)
2010-11-18 06:34 EST, Mickael Istria CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Golubev CLA 2006-06-23 11:34:23 EDT
Actually if gmfgraph Figure has Font or Color defined, generated code creates new instance of SWT Font/Color for each figure instantiation. 
This instance is never disposed, thus, creation of, say, 1000 colored figure instances will probably fail with "No More Handles" SWT exception. Even worse, the same exception may be reproduced with significatly less amount of figures just by reopening of the diagram. 

Expected: The org.eclipse.jface.resources.FontRegisry and org.eclipse.jface.resources.ColorRegistry may be used to dramatically reduce the number of blocked system resources. Alos these classes dispose resources at least on Display disposing. 
Thus, these classes should be used by generated Figure's code.
Comment 1 Michael Golubev CLA 2006-06-23 11:56:49 EDT
Created attachment 45186 [details]
Fixes the subj
Comment 2 Michael Golubev CLA 2006-06-26 11:37:41 EDT
Created attachment 45304 [details]
Fixes the subj (alternative way)

Alternative version of the fix. Instead of generating Color- and Font- registry facade (see the first patch), this fix generates colors and fonts as public static final constants. 

In the standalone version of generator, these constants are added into the generated class body like normal static constants. In the InnerClassViewmap version, we can not add them into the figure code (because figure class is not static inner class and can not contain static members). So, with the help from small hack (see [oeg].graphdef.codegen/templates/top/classFooter.jetinc) we are generating the static constants _after_ the inner class body, that is as a constants in the enclosing class. 

NOTE: In contrast to registry-based solution, this approach DOES NOT dispose static colors and fonts anywhere. Though, the number of created instances is still limited to the number of different figure types. 

This change set DOES NOT obsolete the previous one -- any of solutions may be used.
Comment 3 Artem Tikhomirov CLA 2006-06-26 12:47:43 EDT
Alternative patch reviewed, refactored and committed.
Moving to next version as the issue requires thorough attention and risky changes to be done
Comment 4 Richard Gronback CLA 2007-05-07 10:35:58 EDT
Updated target milestone
Comment 5 Artem Tikhomirov CLA 2007-06-19 09:35:32 EDT
there's no change compared with previous version, resources are allocated once but never disposed.
Comment 6 Artem Tikhomirov CLA 2007-10-25 13:48:40 EDT
*** Bug 155983 has been marked as a duplicate of this bug. ***
Comment 7 Artem Tikhomirov CLA 2008-06-02 08:49:02 EDT
Bulk update, target milestone 2.2
Comment 8 Eclipse Webmaster CLA 2010-07-19 22:18:22 EDT
[GMF Restructure] Bug 319140 : product GMF and component
Generation was the original product and component for this bug
Comment 9 Mickael Istria CLA 2010-11-18 06:34:45 EST
Created attachment 183374 [details]
Suggested patch for XPand templates

This patch fixes the Figure template.
Older patches are marked as obsolete since they were patching old JET templates.
Comment 10 Artem Tikhomirov CLA 2010-12-09 22:35:05 EST
(In reply to comment #9)
> Created an attachment (id=183374) [details]

Although ColorRegistry class is a nice latter addition to the Runtime, I don't think it makes a big difference - it is still static collection of colors (never disposed). 

Use of internal FontRegistry is not a good practice. At least, a bugzilla to make it part of API shall be filed, although such bug would only make the use legitimate, not any nicer.

 Appropriate solution would be disposable storage class generated/added to the runtime instead, with explicit cleanup (e.g. invoked once all diagram instances are closed) and/or weak/soft memory management.