Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PCopy vs. _CopyImage
#2
They're not equivalent, the `_CopyImage()` version is leaking memory. The naming is a bit confusing but `PCopy` is basically an older version of `_PutImage` rather than `_CopyImage()`. That said you would be right that using PCopy is getting you in less trouble Big Grin But you can use `_PutImage` to use the 'new' image commands and still stay out of trouble.

The leak is because `_CopyImage()` creates a new image and returns a new handle to it, so when you do `image2& = _CopyImage()` the previous handle stored in `image2&` (returned from the `_NewImage()` call) is overwritten and lost. When you do the `_FreeImage image2&` at the end, you're freeing the handle returned from `_CopyImage()` but the original handle from `_NewImage()` is not freed (and you also can't free yourself it at that point because you no longer know what it was).

A fix would be to do a `_FreeImage image2&` right before the `Image2& = _CopyImage()` (so, you free the old handle before you overwrite it). Alternatively you could store the handle to the copied image in a new integer variable, so - `image3& = _CopyImage()`, `_PutImage , image3&` and then add an extra `_FreeImage image3&` at the end. That way you free all three images at the end, rather than just two of them.
Reply


Messages In This Thread
PCopy vs. _CopyImage - by NakedApe - 07-27-2025, 02:02 AM
RE: PCopy vs. _CopyImage - by DSMan195276 - 07-27-2025, 02:15 AM
RE: PCopy vs. _CopyImage - by SMcNeill - 07-27-2025, 02:36 AM
RE: PCopy vs. _CopyImage - by NakedApe - 07-27-2025, 03:50 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  PCOPY use with hardware and software images TerryRitchie 7 1,623 08-13-2024, 09:19 PM
Last Post: Pete

Forum Jump:


Users browsing this thread: 1 Guest(s)