Archive for the ‘eclipse’ Category
Changing the Filter In ObjectContribution
I faced a problem while creating a XML editor and a contextual popup menu for it, using the templates in the Eclipse.The xml editor was getting displayed, but the pop up was not coming.After struggling for hours together i found out the small mistake in ‘plugin.xml’ file.
the default value for the name filter in the object contribution will be set as ‘plugin.xml’ we need to change it as ‘*.xml’
….
<extension point = “org.eclipse.ui.popupMenus”> <objectContribution id=”org.eclipse.ui.examples.readmetool” objectClass=”org.eclipse.core.resources.IFile” nameFilter=”*.xml”>
….
No context menu for table columns in SWT
We cannot have context menus for table columns in SWT.Only the widgets which extend Control can have contextual popup menu.Since Table column and tree column are widgets but not controls as far as the hierarchy goes they cannot have context menus.
This is the hierarchy of table column:
java.lang.Object | +--org.eclipse.swt.widgets.Widget | +--org.eclipse.swt.widgets.Item | +--org.eclipse.swt.widgets.TableColumn
why SWT does not use garbage collection
The only disadvantage of SWT was that it left the memory handling onto the responsibilty of the programmers.The reason for that is given in this post.
first of all let us see why we need to free the memory at all?
the operating system is going to free the memory any way when the program terminates.So why should the program free the memory?we must remember that even though recent computers have become very powerful with large memories we need to free up the memory constantly since the programs have also become large, consuming the memory extravagantly.
Why not use the garbage collection offered by java?
Garbage collection is performed by java through the mechanism of passing a finalize message to the java object when the resource is not required.But this mechanism is not suitable for SWT since it uses the Operating System Resources to create the Native OS GUI and widgets.
Why should we not use the finalize method for managing OS resources?
The problem with finalize method is that
1.We cannot be sure when it will be called.
2.The execution of the finalize method is not guaranteed. eg: if an exception occurs while the execution of finalize method the exception is ignored!! and whats more the execution terminates abruptly!!
3.The order in which the finalize method executes is never known.It may execute in any order it wants to (may execute even concurrently!).So we will not be sure when the resource gets released.
Conclusion:
“Finalizers are unpredictable, often dangerous, and generally unnecessary. Their use can cause erratic behavior, poor performance, and portability problems.”-Joshua Bloch in his book Effective Java
The rule is very simple for memory management in SWT:
- If you created it, you dispose it (if you didn’t create it, don’t dispose it).
- Disposing the parent disposes the children.
