首页 \ 问答 \ 如何在Java中销毁String池中的引用?(How can I destroy reference from String pool in Java?)

如何在Java中销毁String池中的引用?(How can I destroy reference from String pool in Java?)

字符串是不可变的。 当我宣布:

String a = "abc";
String a1 = "abc";

两个对象都指向相同的位置。 那么如何从String池中销毁这个“abc”引用呢?

我的用例是我正在开发一个内存较少的硬件应用程序,为此,我需要清除String池中的引用以节省内存。


Strings are immutable. When I declare:

String a = "abc";
String a1 = "abc";

Both objects refer to same location. So how can I destroy this "abc" reference from String pool?

My use case is that I am developing a hardware application with less memory and for this, I need to clear the references from String pool to save memory.


原文:https://stackoverflow.com/questions/38584771
更新时间:2023-03-11 19:03

最满意答案

托马斯是对的,但有一个更好的解决方案:

<style type="text/css">

    #content {width: 500px;}

    .align-left { float: left; }
    .align-right { float: right; }

</style>

<div id="content">

    <img class="align-left" src="link to your image" alt="description of your image" width="100" height="100" />
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

    <img class="align-right" src="link to your image" alt="description of your image" width="100" height="100" />
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

</div><!-- end content -->

在这种情况下,class比ID更有用。


Thomas is right but there's a even better solution:

<style type="text/css">

    #content {width: 500px;}

    .align-left { float: left; }
    .align-right { float: right; }

</style>

<div id="content">

    <img class="align-left" src="link to your image" alt="description of your image" width="100" height="100" />
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

    <img class="align-right" src="link to your image" alt="description of your image" width="100" height="100" />
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

</div><!-- end content -->

class are more usefull than ID in this case.

相关问答

更多
  • 你需要隐藏溢出: .carousel { border-radius: 55px 55px 55px 55px; overflow: hidden; ... } You need to hide the overflow: .carousel { border-radius: 55px 55px 55px 55px; overflow: hidden; ... }
  • 您可以使用以下CSS将其放置在图像旁边: .emailForm { width: 260px; /* anything above 260px will fall over to the next line */ /*float: right;*/ /* remove float */ display: inline-block; /* inline-block since you want specific width and height */ height: 434px ...
  • 我会用弯曲的角落或漂亮的立方体 I'd use curvy corners or nifty cube
  • 使父div可拖动,而不是图像。 $(".looking-glass-images").draggable(); Make the parent div draggable, not the images. $(".looking-glass-images").draggable();
  • 托马斯是对的,但有一个更好的解决方案:
    description of your imag  ...
                                    </div>
                            </div>
                        </li>
                        <li class=
    而不是使用全局运算符,找出您希望图像占用的空间(除了圆角之外应该是一个矩形的路径) 然后在绘制图像之前将此路径放在上下文中,调用.clip(),然后绘制图像。 然后在图像的两个角上用圆角绘制图像。 因此,您现在唯一真正的任务是提出您需要的路径。 简而言之: ctx.save(); ctx.beginPath(); // use lineTo and BezierTo here to make the path you want, which is a rectangle the size of the im ...
  • 要使元素在顶部变粘,请添加以下内容: element{ position:sticky; top:0; } 要使元素在底部变粘,您需要替换top:0; bottom:0; element{ position:sticky; bottom:0; } To make a element sticky at the top you add this: element{ position:sticky; top:0; } To make the element sticky at th ...
  • 改变圆角的顺序和css的一点点变化。