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.
[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.
2 answers
Sort by: Most helpful
-
Elliot 6 Reputation points
2021-02-01T12:35:13.387+00:00 -
Ivanich 306 Reputation points
2021-01-27T17:36:24.28+00:00 You can try following method of StorageFileQueryResult: https://learn.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.