Dragging several files takes a lot of RAM/CPU. Bug in my code or framework leak?

Hi,

In a DesktopListbox (also reproducible using a DesktopTable), I’m storing folderitems in each row (in its RowTag). I’m wanting to provide drag&drop support.

What I’m seeing is a huge CPU and RAM peak when I start dragging a dozen rows (30 in my latest test).
When this happens, I can see my app’s memory usage climbing to, say, 125 GB in around 20 seconds, with the CPU running near 100% and the app freezing (during the attempt to drag the rows). With more items, if I don’t force quit the app, the whole system can quickly become unresponsive, even the clock hangs, and the computer eventually restarts.
But since I could not find reports about this issue, I’m thinking there’s a problem in my code (otherwise, someone else would already have reported it). I’m finding drag&drop in Xojo isn’t always straightforward, especially when dealing with multiple items.

Here’s my current code (DragRow event):

Var IsFirstItem As Boolean=True 'Don't call “AddItem” for the first row, since an item is already created

for i as Integer=0 to me.LastRowIndex
  if me.RowSelectedAt(i) then
    Var f As FolderItem=me.RowTagAt(i)

    if f<>nil then
        if not IsFirstItem then 'Add an item for subsequent rows only
          Var y As Integer=(i-me.ScrollPosition)*me.RowHeight 'Get the row's displayed position

          drag.AddItem(0,y,me.Width-15,y+me.RowHeight)
        end if
    
      drag.FolderItem=f
      IsFirstItem=False
    end if
  end if
next
Return True

The only way in Xojo to have several items in a drag is to use AddItem, which I suspect uses too much RAM (framework bug). But if this is correct, I’m guessing it should already have been reported by someone else.
Thoughts?

How many rows/folderitems do you have in the listbox/table? Do you have an example to test?

In my latest use, I had around 2700 rows (but 30 rows suffice to produce the problem).
I’ll make a sample very soon.
Thanks.

Actually, that’s no longer needed. I found the culprit (with help from AI).
What I was unaware of, is that “recent” versions of MacOS handle drag operations differently when no picture is provided (my code didn’t provide any picture, on purpose). Here’s what I learnt from AI:

macOS snapshots and composites every DragItem rectangle. When you call drag.AddItem without setting a DragPicture, Xojo asks macOS to capture a screenshot of the screen/control at those coordinates for each item. With 30+ items—and progressively larger Height values—macOS attempts to allocate and composite dozens of massive Retina textures simultaneously, causing WindowServer and your app’s memory to explode to 125 GB.

I’m now introducing pictures in my drag operation.
It would have been nice if Xojo could provide a way to add several items without asking the OS to capture a screenshot for each AddItem call.

I’ve always done drags with drag picture. The observed behavior still is a bug or at least a very suboptimal design.

I agree. If I find time, I’ll create a bug report.

Holy cow! I need to open Activity Monitor before running an example. This used over 40 GB of memory.

macOS: excessive memory and CPU when dragging multiple files without a DragPicture
https://tracker.xojo.com/xojoinc/xojo/-/work_items/82293

Thanks a lot for having made this report! Additionally, it’s well written.

William squashed the bug for the next version (whatever # it will be).

It says under milestone 2026r4.

I do not looked there… :wink:

Now you know where to look :wink: