07-27-2025, 02:15 AM
(This post was last modified: 07-27-2025, 02:17 AM by DSMan195276.)
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
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.
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.

