question

Elliot-7999 avatar image
0 Votes"
Elliot-7999 asked ·

[UWP] RuntimeBroker.exe using gigs of memory

RuntimeBroker.exe seems to be a go-between for UWP accessing the file system.

Here is a UWP app button click done in c++/winrt. Just use it to open an entire drive or c:\program files and RuntimeBroker.exe can use more than a few gigs. Takes a very long time.

     Windows::Foundation::IAsyncAction MainPage::ClickHandler(IInspectable const&, RoutedEventArgs const&)
     {
    
         std::wstring  _debugMessage =  L"ClickHandler started";
         OutputDebugString(_debugMessage.data());
    
         Windows::Storage::Pickers::FolderPicker _folderPicker;
                                                 _folderPicker.FileTypeFilter().Append(winrt::hstring(L"*"));
    
         winrt::Windows::Storage::StorageFolder    _folder = NULL;
    
         _folder = co_await _folderPicker.PickSingleFolderAsync();
    
    
         co_await winrt::resume_background();
    
         auto _storageFiles = _folder.GetFilesAsync(Windows::Storage::Search::CommonFileQuery::OrderByName).get();
    
         _debugMessage = std::to_wstring(_storageFiles.Size());
         OutputDebugString(_debugMessage.data());
    
         co_await winrt::resume_foreground(this->Dispatcher());
    
         myButton().Content(box_value(L"Clicked"));
     }

Runtimebroker.exe seems to hold about 60k per StorageItem held. It is probably therefore holding a thumbnail pic (just a guess), which is much bigger than many of the files. Horrendously inefficient.

windows-uwpwindows-uwp-runtime
· 5
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@Elliot-7999 Runtime Broker is an official Microsoft core process that used to determine whether Universal apps you got form the Windows Store are declaring all of their permissions, like being able to access your location or microphone. You could refer to the link about Runtime Broker is using too much memory.

0 Votes 0 ·

Yes that's what I do. This issue is a glaring flaw (albeit easy for Microsoft to fix); a UWP app can make the OS unstable just by opening lots of files.

0 Votes 0 ·

@Elliot-7999 Has the method provided by Ivanich resolve your problem? If you have any concerns, please feel free to contact us.

0 Votes 0 ·
Show more comments
Ivanich avatar image
0 Votes"
Ivanich answered ·

You can try following method of StorageFileQueryResult: https://docs.microsoft.com/en-us/uwp/api/windows.storage.search.storagefilequeryresult.getfilesasync?view=winrt-19041#Windows_Storage_Search_StorageFileQueryResult_GetFilesAsync_System_UInt32_System_UInt32_

It could help to process files page by page and maybe it will help RuntimeBroker to cleanup memory on the fly.

· 1 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

That could be a helpful work-around.
I think that holding on to a StorageFile object causes the system to keep something in runtimebroker.exe's process. And it looks to weigh-in at something like 50kbytes.
This very badly needs to change.

0 Votes 0 ·
Elliot-7999 avatar image
1 Vote"
Elliot-7999 answered ·

When we hold on to a StorageFile object in a UWP app, Windows holds on to about 60k per object in RuntimeBroker.exe.
It seems that the only solution is to not hold very many StorageFile objects.

· 1 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@Elliot-7999 It could be a try to keep your application not hold too many StorageFile objects. If you have a request for a better performance of RuntimeBroker.exe, you could go to the Feedback Hub and submit a feedback.

0 Votes 0 ·