 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Phuoc Guest
|
Posted: Sat Jul 30, 2005 2:58 pm Post subject: StretchDraw() in TThread causes Memory Leak |
|
|
In my program, I'm using StretchDraw() in a thread which is causing memory
leak.
When I use Synchronize() and move the execution of StretchDraw() into the
main thread, the memory problem is gone.
The access of the canvas in the threads are surrounded by lock/unlock.
There are some OTHER canvases in the main threads which are not
locked/unlocked. Is that the reason?
When I lock a canvas do I have to lock before everything, also changing
color, fonts etc.?
or only before modification of the bitmap, i.e. Draw, Copy etc?
thanks
Phuoc Can HUA
--
===============================
I'm using BCB5 on XP Home
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Sat Jul 30, 2005 7:16 pm Post subject: Re: StretchDraw() in TThread causes Memory Leak |
|
|
"Phuoc" <xyz.home (AT) xyz (DOT) huaonline.com.xyz> wrote
| Quote: | In my program, I'm using StretchDraw() in a thread which is causing
memory leak.
|
How do you know that? How are you measuring it? How do you know that your
own code isn't leaking the memory? What does your actual code look like?
| Quote: | When I lock a canvas do I have to lock before everything, also
changing color, fonts etc.? or only before modification of the
bitmap, i.e. Draw, Copy etc?
|
All work done in a separate thread has to be locked. Otherwise, the Canvas
is not protected at all. Fortunately, the VCL does most of the locking
internally for you. But there are times when you should still lock
manually.
Gambit
|
|
| Back to top |
|
 |
PC HUA Guest
|
Posted: Sun Jul 31, 2005 12:46 pm Post subject: Re: StretchDraw() in TThread causes Memory Leak |
|
|
On Sat, 30 Jul 2005 12:16:40 -0700, Remy Lebeau (TeamB)
<no.spam (AT) no (DOT) spam.com> wrote:
| Quote: |
"Phuoc" <xyz.home (AT) xyz (DOT) huaonline.com.xyz> wrote in message
news:op.suqejhkpewlac1 (AT) centrino (DOT) ..
In my program, I'm using StretchDraw() in a thread which is causing
memory leak.
How do you know that? How are you measuring it?
I found that when I noticed that the system became very slow after my |
program has been running for a while. Then I checked the Performance in
Windows Task Manager.
I can see 'Page File Usage History' increasing and the available Physical
Memory getting down.
| Quote: | How do you know that your
own code isn't leaking the memory?
When I comment that line of code with StretchDraw() (one single line) the |
available memory gets up and down within a range. I also replaced it with
Draw() it's fine as well. When I move that one line into main thread with
a Synchronize routine it's okay.
| Quote: | What does your actual code look like?
Basically, it's a slide show which loads JPEG images and stretches/shrinks |
it for display. One TJPEGImage is used repeatly and the image is
StretchDraw() in 2 TBitmap's alternatively.
StretchDraw() was written in the main thread originally. But when the
image is too large the StretchDraw() interrupts the background (MIDI)
music (although the music routine is running on a seperate thread). It was
better when I increased the priority of the music thread temporary before
the StretchDraw(). But I thought it's better to put the StretchDraw() into
the same thread as the image is loaded and I set the priority of that
thread to very low.
Apart from the memory problem the music is running smoothly.
| Quote: | All work done in a separate thread has to be locked.
So, you mean also setting colors etc. |
If I have more than one thread using Canvas should I always use
lock/unlock wherever I can regardless whether it's required, just for
safty?
thanks
Phuoc Can HUA
--
==============================
I'm using BCB5 on XP Hpme
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|