We are writing a diagnostic tool that needs to be run for many hours at a time, but we encounter a cryptic Memory Exception when we try to remove items from the CheckedListBox after the application has launched a couple of hours.
First we tried using checkedListBox.Items.Clear();
, and after some Googling we tried to do something like the following:
for (int i = checkedListBox.Items.Count - 1; i >= 0; i--) { checkedListBox.Items.RemoveAt(i); }
Unfortunately, the above did not solve the problem. I found this idea on the MSDN forums, but I canβt find a link for life again this morning. However, this forum said that someone was profiling their application and found a memory leak in CheckedListBox.Items.Clear()
.
Does anyone know about functional work?
EDIT: FingerTheCat's answer temporarily resolved our issue, so now I will mark it as an answer. However, we started combing the code to try and find the real problem. Unfortunately, the current implementation is mostly spaghetti code, so it may be a few days before we find anything.
source share