嵌套词典:内存使用问题 [英] Nested Dictionaries: memory usage question

查看:75
本文介绍了嵌套词典:内存使用问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好.

假设我们在安全(由GC管理)代码中有一个实例:
Dictionary<Guid, Dictionary<int, SomeClass>> dictionary;

请足够好",
调用dictionary.Clear()进行重建(重新填充),
还是应该为嵌套项目(不再需要,由new分配)调用它? :)

外字典条目的计数平均为100,
内部字典的条目数可以超过10000
并且可以随时通过用户的鼠标单击来重建(重新填充)...

...我也应该明确地配置和重建对象吗?

谢谢!

-
/值类型更正/编辑

Hello.

Assumed we have an instance in the safe (managed by GC) code:
Dictionary<Guid, Dictionary<int, SomeClass>> dictionary;

Would it be "enough properly", please,
to call the dictionary.Clear() to rebuild (refill) it,
or it should be called for the nested (no more needed, allocated by new) items too ? :)

The count of the outer dictionary''s entries averages 100,
the entries'' count of the inner dictionaries can exceed 10000
and it can be rebuilt (refilled) by an user''s mouse click at any time...

...should I dispose and reconstruct the objects explicitly too ?

Thank you !

--
/the value type corrected/edit

推荐答案

您应更改此设计恕我直言.我在这里可以看到几个问题:

1.嵌套的泛型. MS代码分析将根据您的设置将其显示为错误.
2.您正在使用object作为Dictionary中的值.破坏了拥有强类型集合的全部目的.

如果您使用的是.Net 3.0或更高版本,请进行自定义排序,或者如果您使用的是.Net 2.0,请编写您自己的具有适当属性的类.
You should change this design IMHO. There are a couple of problems I can see here:

1. Nested generics. MS code analysis will show that as error depending on the settings you have.
2. You are using object as a value in the Dictionary. The defeats whole purpose of having a strongly typed collection.

If you are using .Net 3.0 or above, go for custom colelction or in case you are using .Net 2.0, write your own class with suitable properties in it.


这篇关于嵌套词典:内存使用问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆