Lightroom Classic 16 SDK: LrView "picture" view keeps about 123 MB per megapixel each time it shows an image, not freed on close
Each time an LrView picture view displays a JPEG file, Lightroom Classic's memory grows by about 123 MB per megapixel of the image, and closing the dialog doesn't give it back. It happens when a dialog opens with the picture's value set, and again each time the value changes in an open dialog. In my runs the memory was still in use several minutes later, and quitting Lightroom was the only way I found to get it back.
I found it while building a plugin that shows a 3×3 grid of Lightroom renders in picture views. Each reopen of its dialog cost about 0.9 GB. After about ten reopens the Mac kernel-panicked (watchdog timeout, low swap space), and the panic report lists Lightroom at 11.8 GB, by far the largest process on a 16 GB machine. That was on 15.4.1; it still happens on 16.0.1.
Environment: Lightroom Classic 16.0.1, macOS 15.8.2 (24H232), MacBook Pro M1, 16 GB. I haven't tried Windows.
Minimal code (a menu script; set the two paths to any two large JPEGs, for example 2880×1920, and watch Lightroom in Activity Monitor):
local LrBinding = import 'LrBinding'
local LrDialogs = import 'LrDialogs'
local LrFunctionContext = import 'LrFunctionContext'
local LrTasks = import 'LrTasks'
local LrView = import 'LrView'
local FIRST_JPEG = '/path/to/first.jpg'
local SECOND_JPEG = '/path/to/second.jpg'
local SWITCH_COUNT = 2
LrFunctionContext.postAsyncTaskWithContext('picture-leak', function(context)
local properties = LrBinding.makePropertyTable(context)
properties.image = FIRST_JPEG
local viewFactory = LrView.osFactory()
local contents = viewFactory:column {
bind_to_object = properties,
viewFactory:picture { value = LrView.bind('image'), width = 1074, height = 716 },
}
local isOpen = true
LrTasks.startAsyncTask(function()
for switchNumber = 1, SWITCH_COUNT do
LrTasks.sleep(2)
if not isOpen then return end
properties.image = (switchNumber % 2 == 1) and SECOND_JPEG or FIRST_JPEG
end
end)
LrDialogs.presentModalDialog { title = 'Picture leak', contents = contents }
isOpen = false
end)
With two 2880×1920 JPEGs on 16.0.1, Lightroom went from about 0.9 GB to 1.6 GB on the open, peaked at 3.9 GB during the two switches, and settled at 2.97 GB: about 680 MB kept for each image shown, including the second switch, back to the file already shown. None of it was freed when the dialog closed.
A plugin that does this with memory logging and safety stops is attached in the first reply.
Steps to reproduce with the attached plugin (no catalog access; macOS only, since it reads memory with pgrep and top):
- Quit and reopen Lightroom.
- File > Plug-in Manager > Add, and pick
picture-leak.lrdevplugin. - Library > Plug-in Extras > Run picture leak repro, and click Continue at the warning (the run uses up to 3 GB until Lightroom quits).
- Leave it for about 20 seconds. The dialog opens and closes by itself, and the plugin logs Lightroom's memory (
phys_footprint, the figure Activity Monitor shows, read withtop, in MiB) after each step.
The plugin's dialog holds a single 1074×716 picture view. It opens three times:
- once with the picture bound to an empty value, as a control;
- once with a literal value from
_PLUGIN:resourceId, with no binding or property table; - once with the picture bound to the path of a 2880×1920 JPEG, then, with that dialog still open, switched to a second 2880×1920 JPEG and back to the first.
On my laptop Lightroom's standard previews are 2880×1920 (Catalog Settings > Standard Preview Size: Auto (2880px)), and that is the size requestJpegThumbnail returned when my plugin asked for a render to fill a view this size. My plugin shows those renders from temp files, so it has to bind the picture to absolute paths.
Expected: memory goes up while an image is shown and comes back down when it is replaced or the dialog closes.
Actual (Lightroom Classic 16.0.1, from the plugin's log, Lightroom freshly started):
start: 1071 MB (Lightroom pid 87134)
Empty: bound, no image: 1054 MB (-17 MB)
Fixed: literal resourceId, no binding, 2880x1920 JPEG: 1753 MB (+699 MB)
Cycle: bound path, first 2880x1920 JPEG: 2430 MB (+677 MB)
Cycle: switched to a second 2880x1920 JPEG: 4018 MB (+1588 MB)
stopping before "Cycle: switched back to the first JPEG (same file again)": predicted growth 4535 MB passes the 3200 MB limit
The empty picture costs nothing. The literal resourceId value with no binding costs about 700 MB, the same as the bound path, so the binding and property table aren't the cause. The switch in the open dialog read about 1.6 GB (15.4.1 gave +1625 MB). That reading is taken 2 seconds after the switch, and it looks like a temporary peak: with the minimal code above, memory went over the kept amount by about 1 GB during the switches and came back down a few seconds later. The plugin then stopped itself before the last step to stay under its 3.2 GB limit.
The same run on 15.4.1:
start: 899 MB (Lightroom pid 62132)
Empty: bound, no image: 884 MB (-15 MB)
Fixed: literal resourceId, no binding, 2880x1920 JPEG: 1589 MB (+705 MB)
Cycle: bound path, first 2880x1920 JPEG: 2291 MB (+702 MB)
Cycle: switched to a second 2880x1920 JPEG: 3916 MB (+1625 MB)
stopping before "Cycle: switched back to the first JPEG (same file again)": predicted growth 4642 MB passes the 3200 MB limit
The results below are all from 15.4.1. An earlier run of the same cycle, with four different 2880×1920 JPEGs (the picture bound through the dialog's bind_to_object, as in the minimal code) and no empty or literal-value steps, gave:
start: 884 MB
Cycle image 1 of 4 shown: 1573 MB (+689 MB)
Cycle image 2 of 4 shown: 2252 MB (+679 MB)
Cycle image 3 of 4 shown: 2928 MB (+676 MB)
Cycle image 4 of 4 shown: 3605 MB (+677 MB)
end, dialog closed: 3604 MB (-1 MB)
That is about 680 MB for each 2880×1920 image (the JPEG files are 190 to 330 KB). A plugin that shows a large render and lets you step through a few variations uses gigabytes within a minute.
Earlier versions of the repro also varied the image and view sizes, one open per step, with Lightroom not freshly started (it was at 1729 MB):
B empty picture, 600x400 view: 1708 MB (-21 MB)
A 1200x800 JPEG, 600x400 view: 1837 MB (+129 MB)
C one dialog, 1200x800 JPEG switched to another, before switching: 1955 MB (+118 MB)
C one dialog, 1200x800 JPEG switched to another, after switching: 2072 MB (+117 MB)
D 2148x1432 JPEG, 600x400 view: 2450 MB (+378 MB)
E 1200x800 JPEG, 1074x716 view: 2585 MB (+135 MB)
end, dialog closed: 2577 MB (-8 MB)
- An empty picture costs nothing (B).
- 1200×800 (0.96 MP) cost 118 to 129 MB and 2148×1432 (3.1 MP) cost 378 MB, about 123 MiB per megapixel. The 2880×1920 runs fit the same rate. That is close to 128 bytes per pixel, in case it helps find what is being kept.
- Changing the image in an open dialog costs about the same as opening one (C). In a second run C's two steps split differently (+162 and +78 MB), with the same total.
- A view with 3.2 times the area cost 135 MB against 129 MB (E), so the cost follows the image's pixel count and the view's size makes little difference.
- Showing the same file again costs the same again: opening the dialog twice with the same 1200×800 JPEG cost +126 and +118 MB, and switching back and forth between two files cost about 118 MB every time.
At that rate a full-size 24 MP image would cost about 3 GB each time it is shown (a prediction: an earlier version predicted it and skipped the step to stay under its limit). The first version of the repro, with nine pictures per dialog and more repetitions, took Lightroom to 30 GB, measured from outside Lightroom while it ran.
I haven't found a workaround: a picture leaks on every image it shows, fixed or changing. If there's a way to make a picture release its image, or a different view I should be using to show a JPEG file, I'd like to know.
