No more “No more handles”March 24, 10Charles SouillardCTO and co-founder of BonitaSoftCharles Souillard – CTO and co-founderwww.bonitasoft.com | © BonitaSoft S.A.
March 24, 10Charles Souillard – CTO and co-founderwww.bonitasoft.com | © BonitaSoft S.A.1Tech TalkOverviewWhatis a « handle »?The « no more handles » errorBest practicesWhatyoushould knowTracking the number of handles
March 24, 10Charles Souillard – CTO and co-founderwww.bonitasoft.com | © BonitaSoft S.A.2Whatis a handle?Mandatorystepto access a system resource, for example:Files
Threads
Graphics (images, colors, fonts)A handlecontains:The resourceaddress
The resourcetypeMarch 24, 10Charles Souillard – CTO and co-founderwww.bonitasoft.com | © BonitaSoft S.A.3« No more handles » error
March 24, 10Charles Souillard – CTO and co-founderwww.bonitasoft.com | © BonitaSoft S.A.4« No more handles » errorThe more objects a diagram contains, the sooner the error is thrownThis error shows up whenNew Image(…) -> System.getHandle()
If a handle is available, access the resource
If there are no more handles available, SWT will throw “no more handles”Memory taken for handles increases dramatically on all OSEasy to reproduce on Windows (limited pool)
March 24, 10Charles Souillard – CTO and co-founderwww.bonitasoft.com | © BonitaSoft S.A.5Best practicesTreat handles much like Java StreamsRule 1: If you created it, you dispose of it (because the GC can’t!)Rule 2: Dispose of the parent – this also disposes of the childrenRule 3: Allocate resources in activate() and dispose them in deactivate()Rule 4: Use resources from registries as much as possible; no need to (don’t!) dispose of them:AbstractUIPlugin, JFaceResources, ColorConstantsMarch 24, 10Charles Souillard – CTO and co-founderwww.bonitasoft.com | © BonitaSoft S.A.6Whatyoushouldknow...It IS necessary to dispose of used handles as they consume a lot of memoryThe GC does NOT reclaim handlesDisposing of handles in Object.finalize() does NOT worknondeterministic:  an object could be marked to be collected but not released immediately
not safe: if an exception is thrown before disposalMarch 24, 10Charles Souillard – CTO and co-founderwww.bonitasoft.com | © BonitaSoft S.A.7UsingS-Leak to trackhandlesS-Leakwww.eclipse.org/swt/tools.php
S-Leak is a simple tool that monitors SWT graphics resourcesIntercept SWT creation/disposalUpdate site www.eclipse.org/swt/updates/3.5Add S-Leak view to your Perspectivelayout.addStandaloneView: “org.eclipse.swt.tools.views.SleakView”
March 24, 10Charles Souillard – CTO and co-founderwww.bonitasoft.com | © BonitaSoft S.A.8UsingS-Leak to trackhandlesSetup launch configurationAdd the org.eclipse.swt.toolsplugin and its dependenciesEnable tracing options:org.eclipse.ui/debug

Eclipsecon 2010 - Charles Souillard - BonitaSoft - No More Handles

  • 1.
    No more “Nomore handles”March 24, 10Charles SouillardCTO and co-founder of BonitaSoftCharles Souillard – CTO and co-founderwww.bonitasoft.com | © BonitaSoft S.A.
  • 2.
    March 24, 10CharlesSouillard – CTO and co-founderwww.bonitasoft.com | © BonitaSoft S.A.1Tech TalkOverviewWhatis a « handle »?The « no more handles » errorBest practicesWhatyoushould knowTracking the number of handles
  • 3.
    March 24, 10CharlesSouillard – CTO and co-founderwww.bonitasoft.com | © BonitaSoft S.A.2Whatis a handle?Mandatorystepto access a system resource, for example:Files
  • 4.
  • 5.
    Graphics (images, colors,fonts)A handlecontains:The resourceaddress
  • 6.
    The resourcetypeMarch 24,10Charles Souillard – CTO and co-founderwww.bonitasoft.com | © BonitaSoft S.A.3« No more handles » error
  • 7.
    March 24, 10CharlesSouillard – CTO and co-founderwww.bonitasoft.com | © BonitaSoft S.A.4« No more handles » errorThe more objects a diagram contains, the sooner the error is thrownThis error shows up whenNew Image(…) -> System.getHandle()
  • 8.
    If a handleis available, access the resource
  • 9.
    If there areno more handles available, SWT will throw “no more handles”Memory taken for handles increases dramatically on all OSEasy to reproduce on Windows (limited pool)
  • 10.
    March 24, 10CharlesSouillard – CTO and co-founderwww.bonitasoft.com | © BonitaSoft S.A.5Best practicesTreat handles much like Java StreamsRule 1: If you created it, you dispose of it (because the GC can’t!)Rule 2: Dispose of the parent – this also disposes of the childrenRule 3: Allocate resources in activate() and dispose them in deactivate()Rule 4: Use resources from registries as much as possible; no need to (don’t!) dispose of them:AbstractUIPlugin, JFaceResources, ColorConstantsMarch 24, 10Charles Souillard – CTO and co-founderwww.bonitasoft.com | © BonitaSoft S.A.6Whatyoushouldknow...It IS necessary to dispose of used handles as they consume a lot of memoryThe GC does NOT reclaim handlesDisposing of handles in Object.finalize() does NOT worknondeterministic: an object could be marked to be collected but not released immediately
  • 11.
    not safe: ifan exception is thrown before disposalMarch 24, 10Charles Souillard – CTO and co-founderwww.bonitasoft.com | © BonitaSoft S.A.7UsingS-Leak to trackhandlesS-Leakwww.eclipse.org/swt/tools.php
  • 12.
    S-Leak is asimple tool that monitors SWT graphics resourcesIntercept SWT creation/disposalUpdate site www.eclipse.org/swt/updates/3.5Add S-Leak view to your Perspectivelayout.addStandaloneView: “org.eclipse.swt.tools.views.SleakView”
  • 13.
    March 24, 10CharlesSouillard – CTO and co-founderwww.bonitasoft.com | © BonitaSoft S.A.8UsingS-Leak to trackhandlesSetup launch configurationAdd the org.eclipse.swt.toolsplugin and its dependenciesEnable tracing options:org.eclipse.ui/debug