Hiya,
In previous articles, I've explained how Jing for Windows (winJing) has had issues with poor memory management and that, though we've cleaned them up, Jing may still appear to occupy a fair bit of memory.
Investigating and fixing these memory issues has been quite an adventure and I thought I'd share...in slightly cutesy form.
[fade in]
Jing's Memory Usage
Finding, Fixing and Faking(?)
{Opening credits go here}In the beginning, Jing was a good application.
It allowed me to share quickly and simply.
It stayed out of my way, but was there when I needed it.
However, it was the biggest memory hog on my machine. And as one of its developers, that was very embarrassing. So I made some time to see what I could do about it.
To lay a baseline, I did seven full screen (dual monitor) image captures and saved each to the Desktop.
The resulting Jing memory usage was ridiculous.

After each capture, the memory lept a mile and never leveled off or decreased. The unbounded and continuous growth was a strong indicator of poor memory management on our part.
So, I set off looking for problems. And golly did I find some doozies.
Shame on me.
After taking some time to track those down and mop them up, I repeated the seven image captures.
After the first three captures, the Mem Usage leveled out and remained pretty much unchanged thru capture seven.
The worst memory management problems seemed to be fixed.
'Well that's better' I thought...er...said...outloud...to myself.
"Hmm...But I know what might be best..."
The .NET framework (
which winJing uses ) cleans up unused memory via something called 'garbage collection'. It does this infrequently because it has to completely stop the application and it takes a bit of processor time.
But I figured, maybe I could call it manually.
I mean, I know what I'm doing, right?
I am so smart! S - M - R - T! And all that.
So I did it manually and this is what I got:

"Cool! Yup. That's the best." I thought.
"But I should probably be sure there isn't something bester."
I did a little looking around and eventually I found a function...a special, magical function.
Real Harry Potter stuff.
And bam! Pow!
"Wow! That's the Bestest! I've shrunk Jing to 29 MB of memory!"
That's impressive, especially for a multimedia .NET application.
I was pleased with myself, but unfortunately, it wasn't true.
As I have stated in
this article, only looking at 'Mem Usage' can be misleading.
What I really wanted to look at was the Virtual Memory Size ('VM Size' in XP or 'Commit Size' on Vista). That would more accurately reflect the affect my code changes were having.
If we look at Virtual Memory Size, we can see the fuller story of my improvements, and reveal the true result of the amazing memory shrinking function.
Good Jing (poorly managed memory):
Better Jing (better memory management):
Best Jing (better memory management and manual garbage collection):
Bester Jing? (better memory management, manual garbage collection and magic (Jinguloso! with wand flick)):
Now, I think comparing these numbers directly, requires a big lump of salt, because the .NET framework is managing the memory. But I think the expansive differences here make it validish to do.
So, cleaning up my poor memory management gained me about 167 MB!
167MB...wow...how embarrassing.
Attempting to do my own garbage collection got me another 32
MB.But at what cost?
Garbage collection has to stop the entire application and is
CPU intensive. And when done manually, it has to be called twice to be 'sure' it worked.
Lastly, my special, magical function resulted in a
HUGE 103 MB savings in Mem Usage even after the other 'improvements'!
But it didn't do anything to reduce winJings actual memory size (You can clearly see why the Mem Usage is not the column to watch for memory leaks).
So what
did the special, magical function do?
It forced Jing out of
RAM and into paged memory. It essentially forces the Mem Usage to be as small as possible, but Jing's actual memory size is unchanged.
So, it doesn't make Jing any smaller.
However, that doesn't mean it's not useful.
It is still good to take up less
RAM when you aren't using it. The OS actually calls this magic function when applications are minimized to make room in case any foregrounded applications need it.
Jing, however, is never minimized. It's always there, even when you aren't using it. Because of this, we'll be looking into possibly calling this function in future releases. But we'd only do so if we find it actually improves system performance and is safe.
We won't call it just to fake people out and make Jing's memory size look smaller. :)
As for garbage collection, we decided it's better to let .NET do what it's designed to do, keep an eye on our memory management and
try to explain what is going on to users who inquire why a 'light, simple sharing app' is taking up 200MB of Mem Usage.
So, in the end, I only improved our memory management. But it should be a huge improvement. And we'll continue looking for other improvements as we try to make Jing as lean and mean as possible.
have a good day,
bill 'I think I'll make my own 29 MB build of Jing...it just looks so cool…ignorance is bliss' scanlon