P: Modal dialogs leak Windows GDI objects, crashing Lightroom
Modal dialogs created by LrDialogs.presentModalDialog() fail to release the Windows GDI objects allocated to them, causing LR to silently crash after a relatively small number of invocations of the plugin, if it has lots of LrView controls.
To reproduce on LR 15.1.1 / Windows 11 (Intel):
1. Save the script below to the file "gdi-leak.lua" in the LR Scripts folder.
2. Restart LR.
3. Open Task Manager, click Details view in the left column, right-click the column header "CPU", do Select Columns, check GDI Objects, click OK, and drag the column header "GDI Objects" to the first column position. Then click the column header "GDI Objects" to sort by that column. It should look like:
johnrellis_0-1769051719447.png
3. Do Scripts > gdi-leak. A dialog with 10 columns of 50 rows of text opens.
4. Repeatedly click OK. After about 20 iterations, observe that the number of GDI Objects for Lightroom.exe has reached 10,000, the maximum value for a process.
5. Click Cancel, and then try to use LR. Observe that after up to 15 seconds or so, Lightroom silently crashes.
local LrDialogs = import "LrDialogs"
local LrTasks = import "LrTasks"
local LrView = import "LrView"
local f = LrView.osFactory()
local result
for i = 1, math.huge do
local columns = {}
for col = 1, 10 do
local column = {}
for row = 1, 50 do
table.insert (column, f:static_text {title = col .. " " .. row})
end
table.insert (columns, f:column (column))
end
local result = LrDialogs.presentModalDialog {title = "Iteration " .. i,
contents = f:row (columns)}
if result == "cancel" then break end
end
