简体   繁体   English

使用文本属性会导致内存泄漏吗?

[英]Does using text properties cause memory leaks?

If a string is immutable, and the Text property of a text box is a string type, will that not result in a massive memory leak if my application makes a lot of changes to the text box? 如果字符串是不可变的,并且文本框的Text属性是字符串类型,如果我的应用程序对文本框进行了大量更改,那么这不会导致大量内存泄漏吗?

What is the best practice when working with text properties that are frequently updated? 使用经常更新的文本属性时,最佳做法是什么?

(I'm assuming you're talking about Java or .NET.) (我假设你在谈论Java或.NET。)

will that not result in a massive memory leak if my application makes allot of changes to the text box 如果我的应用程序对文本框进行了大量更改,那么这不会导致大量内存泄漏

No. It may require many strings to be created, but they can then be garbage collected when they're no longer relevant... so there's no leak . 不。它可能需要创建许多字符串,但是当它们不再相关时它们可以被垃圾收集......所以没有泄漏

You need to be somewhat careful about how much garbage you generate, but in the case of a UI the garbage collector is likely to be significantly faster than the UI anyway - I'd expect that you'd get to the point where the UI is failing to keep up with the changes before GC churn becomes an issue. 您需要对产生的垃圾有一点小心,但在UI的情况下,垃圾收集器可能比UI快得多 - 我希望你能够达到UI的目的。在GC流失成为问题之前未能跟上变化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM