转换方法静态方法时的内存占用 [英] Memory usage when converting methods to static methods

查看:107
本文介绍了转换方法静态方法时的内存占用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用ReSharper的,这表明当一个方法的可能的进行静态的。将转换几百方法静态方法增加了内存占用过大的时期

I started using Resharper and it indicated when a method could be made static. Would converting a few hundred methods to static methods increase the memory footprint over a large period of time?

推荐答案

没有 - ?更改为静态方法对记忆没有影响。

No - Changing to static methods has no effect on memory.

第一次一个类型引用(不论是静态还是非静态),任何静态成员被初始化和静态构造函数中运行。

The first time a type is referenced (whether static or non-statically), any static members are initialized and static constructors are run.

不过,如果你只是考虑从非静态静态切换方式,这会对垃圾收集或全部的内存占用量没有影响。

However, if you're just considering switching methods from non-static to static, this will have no effect on garbage collection or total memory footprint.

您只需要担心内存占用如果您更改类成员是静态的成员发生变化。在这种情况下,一旦类型被访问的静态字段将保持有根,并且将不会被通过GC进行收集。这通常只是做必要的时候,由设计 - 你让一个成员静态的,因为你希望它持续

You only have to worry about memory footprint changing if you change class members to be static members. In this case, static fields will stay rooted once the type is accessed, and will not get collected by the GC. This is typically only done when necessary, and by design - you make a member static because you want it to persist.

这篇关于转换方法静态方法时的内存占用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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