Найдите ссылки на объект во времени выполнения

Попытайтесь использовать существующие исключения везде, где возможно. В этом использовании случая InvalidOperationException, потому что входящее значение приносит объект в непоследовательном состоянии. Пользовательские исключения могут быть созданы, когда определенная обработка за пользовательским исключением необходима. В этом случае Вы только выдаете исключение с некоторым текстом, так используйте InvalidOperationException.

При броске InvalidOperationException показывают значение, которое было передано этому методу set.

21
задан user7116 24 September 2009 в 14:22
поделиться

5 ответов

Try using a memory profiler, (e.g. ants) it will tell you what is keeping the object alive. Trying to 2nd guess this type of problem is very hard.

Red-gate gives 14 days trial that should be more then enough time to tack down this problem and decide if a memory profiler provides you with long term value.

There are lots of other memory profilers on the market (e.g. .NET Memory Profiler) most of them have free trials, however I have found that the Red-Gate tools are easy to use, so tend try them first.

15
ответ дан 29 November 2019 в 21:32
поделиться

Вам нужно будет использовать расширение Windbg и Sosex .

! DumpHeap и ! Команды GCRoot могут помочь вам идентифицировать экземпляр и все оставшиеся ссылки, которые поддерживают его работу.

4
ответ дан 29 November 2019 в 21:32
поделиться

I've been using .NET Memory Profiler to do some serious memory profiling on one of our projects. It's a great tool to look into the memory management of your app. I don't get paid for this info :) but it just helped me alot.

3
ответ дан 29 November 2019 в 21:32
поделиться

The garbage collection in .NET is not a counting scheme (such as COM), but a mark-and-sweep implementation. Basically, the GC runs at "random" times when it feels the need to do so, and the collection of the objects is therefore not deterministic.

You can, however, manually trigger a collection (GC.Collect()), but you may have to wait for finalizers to run then (GC.WaitForPendingFinalizers()). Doing this in a production app, however, is discouraged, because it may affect the efficiency of the memory management (GC runs too often, or waits for finalizers to run). If the object still exists, it actually still has some live reference somewhere.

2
ответ дан 29 November 2019 в 21:32
поделиться

Он не собирается, потому что вы не удалили все ссылки на него. GC будет отмечать объекты для сбора только в том случае, если у них нет корней в приложении.

Какие средства вы используете для проверки GC, чтобы узнать, собрал ли он ваш объект?

0
ответ дан 29 November 2019 в 21:32
поделиться
Другие вопросы по тегам:

Похожие вопросы: