correctly Controlling Garbage Collection
correctly Controlling Garbage Collection
- Subject: correctly Controlling Garbage Collection
- From: WareTo Development <email@hidden>
- Date: Fri, 16 Oct 2009 02:17:21 -0400
I saw a couple posting regarding this when Garbage Collection was
originally introduced, but have not seen any discussion since. I do
not believe the issue was ever resolved.
Our application uses Garbage Collection under 10.5 (and now 10.6). We
have several custom views with custom mouse tracking while dragging
(mouse click down event, move move events, then mouse up event). We
track this information in order to implement a pencil drawing tool in
our application. Normally this works smoothly. The tracking is done
often enough so the pencil draws a smooth line. If the user moves his
mouse VERY fast, the mouse move events are greater then a pixel
across, and we draw a line from old point to the new point. This is
acceptable for most case.
We discovered during testing that is some special cases, the mouse
moved events were not being tracked fast enough. This caused what
should of been a smooth line (drawing pixel to pixel) to be drawn as a
straight line (not enough mouse tracking).
Using our development tools, we discovered this was due to garbage
collection.
Ever once in awhile, based on memory usage, the system does a deep
garbage collection operation. If it happens when the pencil is being
drawn, we get badly drawn lines.
Looking at this problem, we could perform better memory management, so
deep garbage collection does not happen that often. This reduces the
problem, but can never eliminate it, since sooner or later the garbage
clean operation must be done.
So we thought the best thing would be to force a garbage collection
operation at a time of our choosing. Normally, this occurs at Mouse
up, after the user has finished his drawing. A split second of garbage
collection then would be barely noticeable by the user.
So, we looked for a call, and thanks to this list we found
objc_collect (OBJC_EXHAUSTIVE_COLLECTION | OBJC_WAIT_UNTIL_DONE);
.
Unfortunately, this does not solve our problem. That call does not
insure a garbage collection operation synchronously, nor shortly after
one returns to the main event loops. It does seem to cause one a short
time later, but by then the user might be drawing with the pen again.
We saw that a couple other people complained about this call not doing
what they expected, but this was a while back, and we have not seen
any new discussions about it.
Has anyone else conquered similar Garbage Collection issues? It would
appear to me, that unless there are better controls then we now know
about, this type of slow down issue would make Garbage Collection
useless for any application that does animation or smooth mouse
tracking.
Thank you!
Steve Sheets
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden