garbage-collection

When will the new String() object in memory gets cleared after invoking intern() method

你说的曾经没有我的故事 提交于 2019-12-30 06:53:07
问题 List<String> list = new ArrayList<>(); for (int i = 0; i < 1000; i++) { StringBuilder sb = new StringBuilder(); String string = sb.toString(); string = string.intern() list.add(string); } In the above sample, after invoking string.intern() method, when will the 1000 objects created in heap (sb.toString) be cleared? Edit 1: If there is no guarantee that these objects could be cleared. Assuming that GC haven't run, is it obsolete to use string.intern() itself? (In terms of the memory usage?) Is

Garbage collector and event handlers

让人想犯罪 __ 提交于 2019-12-30 04:36:06
问题 A quick question. Say that I have a class implemented as in below example. class Subscriber { private Publisher publisher = new Publisher; public Subscriber() { publisher.SomeEvent += new EventHandler(OnEventFired); } private void OnEventFired(object sender, EventArgs e) { } } And somewhere in the program I have a method that looks like this: public void DoSomething() { Subscriber subscriber = new Subscriber(); } Am I right to expect that this would cause a memory leak since subscriber never

Java CMS GC Behaviours

醉酒当歌 提交于 2019-12-30 03:29:05
问题 I have an application that cause to creating lots of garbage. First (and almost one) criteria is low GC pause time. I try different GC parameters using visualgc tool (and gc logs). Best parameters are below. -XX:+UseConcMarkSweepGC -Xmx1172M -Xms600M -XX:+UseParNewGC -XX:NewSize=150M My application run on SunOS 10 with Java 1.6.0_21 . Hardware is 2 x CPU quad core (uname -X result is numCPU = 8). Questions are Observing GC behaviours, New objects creating on eden space until eden is full.

How to request JVM garbage collection (not from code) when run from Windows command-line

家住魔仙堡 提交于 2019-12-30 02:54:45
问题 how could I request Java garbage collection externally, starting the program from JAR (Windows BAT used)? From the Java code I can do it with System.gc() When running a JNLP distribution, I get this "Java console" turned on from Control Panel / Java / ... and this Java console provides manual garbage collection. But... When I'm running the jar from command-line / bat the java console doesn't seem to open. Couldn't find help with a brief googling, maybe somebody here? 回答1: You can use jconsole

git gc --aggressive --prune=all does not remove big file from repository

一笑奈何 提交于 2019-12-30 01:02:14
问题 There are many SO questions regarding "how to remove an accidentally added big file from repo", many of them suggesting using git gc command. However, I find it not working for me and I don't know what's going wrong. Here is what I have done: $ git init Initialized empty Git repository in /home/wzyboy/git/myrepo/.git/ $ echo hello >> README $ git add README $ git commit -a -m 'init commit' [master (root-commit) f21783f] init commit 1 file changed, 1 insertion(+) create mode 100644 README $ du

What is the meaning of the -XX:NewRatio and -XX:OldSize JVM flags?

廉价感情. 提交于 2019-12-30 00:07:12
问题 I am starting my java app with the following command line : java -XX:+PrintCommandLineFlags -verbose:gc -XX:+PrintGCDetails \ -XX:+UseConcMarkSweepGC -jar start.jar The JVM enables the following options: -XX:MaxNewSize=87244800 -XX:MaxTenuringThreshold=4 -XX:NewRatio=7 -XX:NewSize=21811200 -XX:OldPLABSize=16 -XX:OldSize=65433600 -XX:+PrintCommandLineFlags -XX:+PrintGC -XX:+PrintGCDetails -XX:+UseCompressedOops -XX:+UseConcMarkSweepGC -XX:+UseParNewGC Can anyone explains me the meaning of

java garbage collection and null reference

半世苍凉 提交于 2019-12-29 08:18:08
问题 In my studying for OCJP I came across the following question: class CardBoard { Short story = 200; CardBoard go(CardBoard cb) { cb = null; return cb; } public static void main(String[] args) { CardBoard c1 = new CardBoard(); CardBoard c2 = new CardBoard(); CardBoard c3 = c1.go(c2); c1 = null; // do Stuff }} When //doStuff is reached, how many objects are eligible for GC? The correct answer is 2, meaning c1 and its story object. When line //doStuff is reached, c3 is also null. Why isn't it

Excel process still runs after closing in VB.net

江枫思渺然 提交于 2019-12-29 07:56:08
问题 My question is basically just how to end the Excel.exe process that runs when using excel. In the application I open and use an excel workbook with a couple sheets, then leave them for the user to do as they please, my problem is that my application never lets go of the Excel process. If the application is closed before closing excel, the process ends when excel is closed, otherwise if I close my application after closing excel, the process stays running. I've tried a few things I've found

Unexpected result from sys.getrefcount

孤街醉人 提交于 2019-12-29 07:54:30
问题 When I typed: >>> astrd = 123 >>> import sys >>> sys.getrefcount(astrd) 3 >>> I am not getting where is astrd used 3 times ? 回答1: It's not astrd that is referenced three times, but the value 123 . astrd is simply a name for the (immutable) number 123, which can be referenced however many times. Additionally to that, small integers are usually shared: >>> astrd = 123 >>> sys.getrefcount(astrd) 4 >>> j = 123 >>> sys.getrefcount(astrd) 5 In the second assignment, no new integer is created,

Unexpected result from sys.getrefcount

ぐ巨炮叔叔 提交于 2019-12-29 07:54:25
问题 When I typed: >>> astrd = 123 >>> import sys >>> sys.getrefcount(astrd) 3 >>> I am not getting where is astrd used 3 times ? 回答1: It's not astrd that is referenced three times, but the value 123 . astrd is simply a name for the (immutable) number 123, which can be referenced however many times. Additionally to that, small integers are usually shared: >>> astrd = 123 >>> sys.getrefcount(astrd) 4 >>> j = 123 >>> sys.getrefcount(astrd) 5 In the second assignment, no new integer is created,