Technology Questions

Go Back   Technology Questions > Hardware Questions > Mobile Computers > Tablet PC > Tablet PC Software > Tablet PC Developers

Tablet PC Developers Show off your work while discussing with others how to create ink enabled applications.

Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old 05-06-2007, 07:32 AM
tony@heavyenergy.com
Newsgroup Contributor
 
Posts: n/a
Disposing Ink Strokes

Hello,

I wonder if anyone can help me with this. I have found that I can not
properly dispose of Microsoft.Ink.Strokes objects from memory.

My application creates a number of Strokes objects to process the
ink. Some of these are stored in memory for later use and others are
disposed immediately after use.

The following sample code should:
1. Create a Strokes object
2. Create and add some strokes from another ink object
3. Dispose of the Strokes and Ink Object

but it doesn't dispose of the Strokes object:

Using ink As New Ink
Using ss As Strokes = ink.CreateStrokes

' use stroke packetdata from another ink object
For Each s As Stroke In _inkoverlay.Ink.Strokes
Dim propertyDescriptionCollection As New
TabletPropertyDescriptionCollection()
For Each guid As Guid In s.PacketDescription
Dim metrics As TabletPropertyMetrics =
s.GetPacketDescriptionPropertyMetrics(guid)
propertyDescriptionCollection.Add(New
TabletPropertyDescription(guid, metrics))
Next
ss.Add(ink.CreateStroke(s.GetPacketData,
propertyDescriptionCollection))
Next

' Don't leave any strokes floating
ink.DeleteStrokes(ss)

' throw in for good measure - but they still don't
dispose
ss.Remove(ss)
ss.Dispose()
End Using

ink.Dispose()
End Using

I have tried this with and without the "using" statement and the
"Dispose" on the the Strokes but it still doesn't dispose of the
Strokes object from memory.

Each time the statement is run I am left with an additional strokes
collection and resources run low very quickly.

Any assistance will be gratefully received.

Thanks
Tony

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

 
Old 05-06-2007, 07:32 AM
  #2 (permalink)  
Old 05-06-2007, 07:32 AM
Josh Einstein
Newsgroup Contributor
 
Posts: n/a
Re: Disposing Ink Strokes

The first question I have is what makes you think that Ink and Strokes
aren't getting disposed? According to Reflector, both classes simply
unregister from some event handlers and then call Marshal.ReleaseComObject
on the underlying RCW (runtime callable wrapper). Microsoft.Ink is actually
just a thin layer over a COM API.

As I understand it, ReleaseComObject doesn't necessarily release anything -
it just decrements .NET's internal reference count mechanism which in turn
will decrement the COM reference counter when the last RCW is released.
Presumably this is where the COM Ink object physically frees the memory.
Because you can't easily decompile native code, we can only assume that this
is happening when Ink.Dispose is called and there's no evidence to suggest
otherwise.

But in .NET it is not uncommon to see memory usage climb when you're making
allocations in a loop like that. These allocations (such as the integer
arrays which can be potentially large when dealing with ink) are not going
to be freed by the call to Ink.Dispose. Only the garbage collector can do
that and it will take some time to see the effects of the garbage collector.
In fact, time doesn't even have anything to do with it - it's all about
allocations and memory pressure.

I think you should use a profiler (AQTime is the one I use and I highly
recommend it) to see just what is occupying that memory and if so, what's
holding onto it.

--
Josh Einstein (Tablet PC MVP)
Einstein Technologies
Tablet Enhancements for Outlook - Try it free: www.tabletoutlook.com


<tony@heavyenergy.com> wrote in message
news:1177093239.851472.311170@n59g2000hsh.googlegr oups.com...
> Hello,
>
> I wonder if anyone can help me with this. I have found that I can not
> properly dispose of Microsoft.Ink.Strokes objects from memory.
>
> My application creates a number of Strokes objects to process the
> ink. Some of these are stored in memory for later use and others are
> disposed immediately after use.
>
> The following sample code should:
> 1. Create a Strokes object
> 2. Create and add some strokes from another ink object
> 3. Dispose of the Strokes and Ink Object
>
> but it doesn't dispose of the Strokes object:
>
> Using ink As New Ink
> Using ss As Strokes = ink.CreateStrokes
>
> ' use stroke packetdata from another ink object
> For Each s As Stroke In _inkoverlay.Ink.Strokes
> Dim propertyDescriptionCollection As New
> TabletPropertyDescriptionCollection()
> For Each guid As Guid In s.PacketDescription
> Dim metrics As TabletPropertyMetrics =
> s.GetPacketDescriptionPropertyMetrics(guid)
> propertyDescriptionCollection.Add(New
> TabletPropertyDescription(guid, metrics))
> Next
> ss.Add(ink.CreateStroke(s.GetPacketData,
> propertyDescriptionCollection))
> Next
>
> ' Don't leave any strokes floating
> ink.DeleteStrokes(ss)
>
> ' throw in for good measure - but they still don't
> dispose
> ss.Remove(ss)
> ss.Dispose()
> End Using
>
> ink.Dispose()
> End Using
>
> I have tried this with and without the "using" statement and the
> "Dispose" on the the Strokes but it still doesn't dispose of the
> Strokes object from memory.
>
> Each time the statement is run I am left with an additional strokes
> collection and resources run low very quickly.
>
> Any assistance will be gratefully received.
>
> Thanks
> Tony
>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Key Strokes Don't Display at Startup old volunteer Windows XP 11 07-07-2008 08:01 PM
Creating Ink strokes in code. Amr Bekhit Tablet PC Developers 1 05-19-2008 10:00 PM
Strokes from Individual Letters Eli Gibson Tablet PC Developers 1 12-31-2007 06:00 AM
Shortcut Key Strokes Dewayne Windows XP 7 06-07-2007 03:40 AM
Record Ink Strokes? Amy Blankenship Windows XP Tablet PC Newsgroup 0 12-28-2006 02:27 PM


New To Technology Questions? Do You Need Help with Your Computer or Device? Do You Need Help with this site?

All times are GMT -8. The time now is 03:25 AM.


2003 - 2009 All Rights Reserved. Technology Questions

Search Engine Friendly URLs by vBSEO 3.3.0