The Artima Developer Community
Sponsored Link

Java Buzz Forum
Find Leaking SWT Resources with S-Leak

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Scott Delap

Posts: 1154
Nickname: scottdelap
Registered: Sep, 2004

Client / Server application developer.
Find Leaking SWT Resources with S-Leak Posted: Apr 29, 2005 11:19 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Scott Delap.
Original Post: Find Leaking SWT Resources with S-Leak
Feed Title: ClientJava.com
Feed URL: http://www.clientjava.com/archives/wireless_mobile.rdf
Feed Description: Client/Desktop Related Java Development
Latest Java Buzz Posts
Latest Java Buzz Posts by Scott Delap
Latest Posts From ClientJava.com

Advertisement

Recently, I had to track down some GDI handle issues with an Eclipse plugin based application. SWT Resources such as Color, Cursor, Display, Font, GC, Image, Printer, Region, Widget and subclasses allocate system resources in their constructors. As a result you must dispose of them when finished. Normally widgets don't cause that much of an issue because disposing a parent widget disposes its children. However, other objects such as images can quickly add up. In the case of my problem, I had written a label provider that created custom images for each node of a tree. Further compounding matters was the fact that numerious intermediate images were created in the process of deriving each final image. After adding a few quick lines of caching code I went from 500+ GDI handles being created to 20. Finally, I was able to add a dispose listener to release the 20 handles when the label provider was no longer needed. During this process I found a useful tool called Sleak. Sleak tracks resources and where they were allocated. There are both a standalone and Eclipse plugin version of Sleak. The 1.x version runs under Eclipse 2.0. I also found an updated version hid in the Eclipse bug tracker for Eclipse 3.x.

SWT: Managing Operating System Resources
SWT uses operating system resources to deliver its native graphics and widget functionality. Allocating and freeing operating system resources is traditionally an area of programming that is error prone. Languages that include garbage collection, such as the Java language, relieve the programmer from the burden of managing memory, but not from the allocation and freeing of operating system resources. This article discusses the simple strategy used by SWT to help application designers manage operating system resources.

Sleak 1.x
Sleak is a simple tool that monitors SWT graphics resources. (Applications typically don't leak widget resources because of rule 2). You can use Sleak to detect leaks in SWT application code.

The S-Leak Plugin and core, revamped for Eclipse 3.0
For those of you who dont know about S-Leak, it's a dangling resource tracker for SWT based applications. In SWT when we allocate resources such as fonts or images, we have to make sure to dispose them later. However, sometimes we miss them and this guy helps you find the ones you missed. It provides a stack trace of when the resource was created as well as a preview of the resource (if possible). It uses A LOT of Eclipse functionality to accomplish this.

Read: Find Leaking SWT Resources with S-Leak

Topic: Is publicly editing Wiki dreams over? Ward’s C2 has caved in to Wiki Spamming. Previous Topic   Next Topic Topic: Punchy Design

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use