Bug 471543 - Memory leak when sampling a hidden, color-labeled filter layer
Summary: Memory leak when sampling a hidden, color-labeled filter layer
Status: RESOLVED FIXED
Alias: None
Product: krita
Classification: Applications
Component: Filter Layers (show other bugs)
Version: 5.1.5
Platform: Homebrew (macOS) macOS
: NOR normal
Target Milestone: ---
Assignee: Dmitry Kazakov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-06-28 18:40 UTC by code
Modified: 2023-06-29 14:37 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description code 2023-06-28 18:40:41 UTC
SUMMARY
When a tool samples a hidden, color-labeled filter layer Krita starts leaking significant amounts of memory.

STEPS TO REPRODUCE
1. Open a large image (width/height of a few thousand pixels)
2. Create the following layer structure:
  - Filter layer (Color Adjustment Curves, hidden, labeled red)
  - Background (labeled red)
  - Empty layer
3. Set the fill tool to sample the red layers
4. Select the empty layer and start spamming the fill tool

OBSERVED RESULT
After spamming the fill tool a couple dozen times, the memory usage will spike by multiple gigabytes, and that memory won't be freed even if you close the image and open a different one. The memory doesn't seem to be categorized anywhere in the memory indicator, showing up in the total memory used, but not in any of the categories.

EXPECTED RESULT
The memory usage should stay relatively constant

SOFTWARE/OS VERSIONS
macOS Ventura (13.2)

ADDITIONAL INFORMATION
- The same issue occurs with the Fill Tool, Contiguous Selection Tool, or Similar Color Selection Tool
- The issue occurs with any filter I tested (Color Adjustment Curves, Levels, Blur)
- The issue doesn't occur when the filter layer is visible
- Setting the filter layer to visible and using the fill tool again doesn't clear the leaked memory
- The issue doesn't occur when the filter layer is hidden and the fill tool is set to sample the merged image
Comment 1 Dmitry Kazakov 2023-06-29 14:37:56 UTC
Git commit 4c9364617167a1a195713366fc697ba734de2735 by Dmitry Kazakov.
Committed on 29/06/2023 at 14:37.
Pushed by dkazakov into branch 'master'.

Fix a memory "leak" in LambdaCommand used in the fill tool

Lambdas can capture shared pointers, which can potentially prevent
temporary paint devices from being released. That is exactly what
happened in the tagged-fill tool, the reference paint device was
captured by the lambda and never freed (until the undo command is
expelled from the stack).

M  +6    -0    libs/command/kis_command_utils.cpp

https://invent.kde.org/graphics/krita/-/commit/4c9364617167a1a195713366fc697ba734de2735