什么是内部类的合成反向引用
我正在寻找应用程序中的内存泄漏,我正在使用的探查器告诉我寻找这些类型的引用,但我不知道我在寻找什么。有人可以解释一下吗?
谢谢,
埃利奥特
I am looking for memory leaks in my application and the profiler I am using tells me to look for these types of references but I don't know what I'm looking for. Can some one please explain this?
Thanks,
Elliott
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以对 OUTER 类进行合成反向引用,但不能对内部类实例进行合成。
例如
,在此示例中,Inner 具有对 Outer 类的引用。嵌套则不然。如果 Outer 很大,这可能意味着您可以抓住不需要的物体。
简而言之,如果可以的话,将内部类设为
static
。You can have synthetic back reference to an OUTER class, but not inner class instances.
e.g.
In this example, Inner has a reference to the Outer class. Nested does not. If Outer is large this can mean you have can be holding onto an object you don't need.
In short, make inner classes
static
if you can.我认为不存在对内部类的综合引用之类的东西。我认为探查器正在讨论从内部类到其封闭类的引用。这些是在您具有如下代码时创建的:
在上面的代码中,
Inner
的每个实例都有一个与其关联的Outer
实例。该关联是通过Inner
的隐藏合成成员字段维护的,该字段包含对Outer
的引用。如果代码像这样进行更改:
就不会有这样的综合引用。
I don't think there is such thing as synthetic references to an inner class. I think the profiler is talking about references from inner classes to their enclosing classes. These are created when you have code like this:
In the above code, every instance of
Inner
has an instance ofOuter
associated with it. The association is maintained through a hidden synthetic member field ofInner
that contains a reference toOuter
.If the code were changes like so:
there would be no such synthetic reference.