Skip to content

Commit

Permalink
Merge pull request #204 from lostmsu/master
Browse files Browse the repository at this point in the history
* fixed memory leaks in VisibleImage
  • Loading branch information
JakeGinnivan committed Jan 21, 2014
2 parents 74de354 + 009dd8b commit 730583d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/TestStack.White/UIItems/UIItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ public virtual Bitmap VisibleImage
get
{
var displayedItem = new DisplayedItem(new IntPtr(automationElement.Current.NativeWindowHandle));
System.Drawing.Image image = displayedItem.GetVisibleImage();
return new Bitmap(image);
using(System.Drawing.Image image = displayedItem.GetVisibleImage())
return new Bitmap(image);
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/TestStack.White/WindowsAPI/DisplayedItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,10 @@ public virtual Bitmap GetVisibleImage()
{
DeleteDC(compatibleDeviceContext);
ReleaseDC(windowHandle, deviceContext);
img = Image.FromHbitmap(bitmap);
DeleteObject(bitmap);
img = Image.FromHbitmap(bitmap);
DeleteObject(bitmap);
}

return new Bitmap(img);
using (img) return new Bitmap(img);
}
}
}

0 comments on commit 730583d

Please sign in to comment.