garbage-collection

How should the clean-up of Timers declared inside the scope of a function be managed?

放肆的年华 提交于 2020-05-15 00:52:15
问题 In the following code, a Timer is declared inside a function, where it also subscribes to the Elapsed event: void StartTimer() { System.Timers.Timer timer = new System.Timers.Timer(1000); timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed); timer.AutoReset = false; timer.Start(); } Once the function completes, the reference to the Timer is lost (I presume). Does the Elapsed event get unregistered automatically as the object is destroyed, or if not, can the event be

Difference between -XX:+PrintGC and -verbose:gc

醉酒当歌 提交于 2020-05-14 18:57:08
问题 I want to understand the difference between: -XX:+PrintGC and -verbose:gc Apparently these look similar. This article doesn't list the verbose:gc http://www.oracle.com/technetwork/articles/java/vmoptions-jsp-140102.html I also saw these two questions: How to redirect verbose garbage collection output to a file? and https://stackoverflow.com/a/1818039/2266682 but couldn't get much understanding. 回答1: In JDK 8 -verbose:gc is an exact alias for -XX:+PrintGC . However, -verbose:gc is a standard

Do I always need to call URL.revokeObjectURL() explicitly?

女生的网名这么多〃 提交于 2020-05-10 20:52:52
问题 I'm using blob to download files, Problem is I want to keep Object URL even after downloading the file, without making major changes in code base. So one of the option is not to call URL.revokeObjectURL(); Is it safe to depend on browser's garbage collector to avoid any memory leak? Do I always need to call URL.revokeObjectURL(); explicitly ? 回答1: Is it safe to depend on browser's garbage collector to avoid any memory leak? What createObjectURL approximately¹ does is to create a mapping of

JVM - Are WeakReferences collected in minor GC?

我只是一个虾纸丫 提交于 2020-05-08 03:39:40
问题 I was wondering about that since that would make them less useful. If so, is there a way to make memory weakly referenced only "garbage" on major GC? 回答1: The javadoc does not specifically state what the "timescales" are for clearing / breaking WeakReference s. That would make the answer to your question (at least in theory) "it is implementation dependent". Indeed, the JLS spec and javadocs don't even mention major versus minor collections. The whole topic comes is in the "implementation

Is it ok to use same BasicDataSource, Connection, Statement and ResultSet Object in multiple class methods.?

梦想的初衷 提交于 2020-04-30 14:00:19
问题 I have below code which uses static objects of BasicDataSource, Sql Connection, Statement and ResultSet. The code below is working fine, but i just want to know about the safety of using these kinds of coding practices. or how can i optimize the below code so that it can become more stable and can reliable. public class Testing { static BasicDataSource bds = DBConnection.getInstance().getBds(); static Connection con = null; static PreparedStatement stmt = null; static ResultSet rs = null;

Is it ok to use same BasicDataSource, Connection, Statement and ResultSet Object in multiple class methods.?

喜你入骨 提交于 2020-04-30 13:57:09
问题 I have below code which uses static objects of BasicDataSource, Sql Connection, Statement and ResultSet. The code below is working fine, but i just want to know about the safety of using these kinds of coding practices. or how can i optimize the below code so that it can become more stable and can reliable. public class Testing { static BasicDataSource bds = DBConnection.getInstance().getBds(); static Connection con = null; static PreparedStatement stmt = null; static ResultSet rs = null;

Azure Web App Temp file cleaning responsibility

烈酒焚心 提交于 2020-04-10 07:37:11
问题 In one of my Azure Web App Web API application, I am creating temp files using this code in a Get method string path = Path.GetTempFileName(); // do some writing on this file. then read var fileStream = File.OpenRead(path); // then returning this stream as a HttpResponseMessage response My question is, in a managed environment like this (not in VM), do I need to clear those temporary files by myself? Shouldn't Azure itself supposed to clear those temp files? 回答1: Those files only get cleaned

Are there any events that tell an application when garbage collection has occurred?

生来就可爱ヽ(ⅴ<●) 提交于 2020-04-10 04:26:53
问题 I am trying to find a way to know about garbage collection. Either, when it has started, finished or is in process. I really just need some event connected to the collection itself (I think). My issue is that I have a WeakEventManager (written from scratch) and I have cleanup methods that delete and WeakReferences that are no longer alive (WeakReferences are in a Dictionary). The issue is that I have to know when it is time to "clean up". It would be nice to cleanup when the collector is

What are pinned objects?

时光毁灭记忆、已成空白 提交于 2020-03-30 04:37:11
问题 I am trying to find a memory leak using ants memory profiler, and I've encountered in a new term: Pinned objects. Can some one give me a good & simple explanation about what this objects are, How can I pinn/Unpinn objects, and detect who pinned objects? Thanks 回答1: A pinned object is one that is not allowed to move. The garbage collector is normally compacting the memory in that it moves all objects to "one or more clusters". This is to create large chunks of free space. This basically means

Why doesn't the CLR call Dispose automatically

落花浮王杯 提交于 2020-03-26 05:25:08
问题 I'm hoping i know my facts correctly if not please correct me. 1) You use Dispose to clean unmanaged resources, that means no garbage collection for them. 2) Value types are stored on the stack, reference types are stored on the heap and pointers to reference types are stored on the stack(not really sure about this one but i think it's correct) 3) Finilizers are called by the Garbage Collector. 4) Garbage Collection is called by the CLR and not by the user(although the he can) for reference