finalizer

Can I override Dispose to make an entity class that always calls SaveChanges?

会有一股神秘感。 提交于 2019-12-21 20:19:54
问题 This is a fairly fine point, and I expect the answer is "it's not a hot idea to begin with" - that said, it has a points that I'm interested in regardless, if someone is kind enough to indulge. Model Code: public partial class MyEntities : ObjectContext { // the idea is if the object is in a using block, this always gets called? protected override void Dispose(bool disposing) { this.SaveChanges(); base.Dispose(disposing); } } Client Code: using(var model = new MyEntities()) { // do something

Is it possible to run tear down fixture only after all params runs?

吃可爱长大的小学妹 提交于 2019-12-20 03:33:32
问题 For instance if you have: @pytest.mark.parametrize('lang', ["EN", "FR"]) def test_whats_hot_quick_links_are_displayed(self, lang): # Do something here and i have this teardown fixture in conftest: @pytest.fixture(scope='function', autouse=True) def teardown_function(request): def execute_at_the_end(): logging.info("Ending Test Case...") database.clear() request.addfinalizer(execute_at_the_end) So how can i make the teardown function execute only after both EN and FR test runs are executed

Performance implications of finalizers on JVM

你。 提交于 2019-12-19 02:31:48
问题 According to this post, in .Net, Finalizers are actually even worse than that. Besides that they run late (which is indeed a serious problem for many kinds of resources), they are also less powerful because they can only perform a subset of the operations allowed in a destructor (e.g., a finalizer cannot reliably use other objects, whereas a destructor can), and even when writing in that subset finalizers are extremely difficult to write correctly. And collecting finalizable objects is

Good samples of using Finalizers in C#

别说谁变了你拦得住时间么 提交于 2019-12-18 13:09:21
问题 When I read a few articles about memory management in C#, I was confused by Finalizer methods. There are so many complicated rules which related with them. For instance, nobody knows when the finalizers will be called, they called even if code in ctor throws, CLR doesn't guarantee that all finalizers be called when programs shutdowt, etc. For what finalizers can be used in real life? The only one example which I found was program which beeps when GC starts. Do you use Finalizers in your code

How does a “finalizer guardian” work in java?

断了今生、忘了曾经 提交于 2019-12-18 12:59:10
问题 How does a "finalizer guardian" [Effective Java , page 30] work ? Have you used them? Did it solve any specific problem ? 回答1: It solves the problem of the sub-class forgetting to call the finalize method of the super-class. This pattern works by attaching an extra instance with overridden finalize to your super-class. This way, if the super-class goes out of scope, the attached instance would also go out of scope, which would trigger the execution of its finalize , which would in turn call

Why is it always necessary to implement IDisposable on an object that has an IDisposable member?

给你一囗甜甜゛ 提交于 2019-12-18 05:15:09
问题 From what I can tell, it is an accepted rule that if you have a class A that has a member m that is IDisposable, A should implement IDisposable and it should call m.Dispose() inside of it. I can't find a satisfying reason why this is the case. I understand the rule that if you have unmanaged resources, you should provide a finalizer along with IDisposable so that if the user doesn't explicitly call Dispose, the finalizer will still clean up during GC. However, with that rule in place, it

Aren't destructors guaranteed to finish running?

a 夏天 提交于 2019-12-18 04:53:01
问题 Destructors are weird . I was attempting to eliminate the need of using the disposable pattern by using 'smart' reference management, ensuring that the garbage collector could collect objects at the correct time. In one of my destructors I had to wait for an event from another object, which I noticed it didn't. The application simply shut down and the destructor was terminated in middle of execution. I'd expect a destructor is always allowed to finish running, but as the following test

What are the Finalizer Queue and Control+ThreadMethodEntry?

ε祈祈猫儿з 提交于 2019-12-18 04:52:44
问题 I have a WindowsForms app that appears to leak memory, so I used Redgate's ANTS Memory Profiler to look at the objects I suspect and find that they are only held by objects already on the Finalizer Queue . Great, exactly what is a the Finalizer Queue? Can you point me to the best definition? Can you share any anecdotal advice? Also, all the root GC objects on the Finalizer Queue are instances of System.Windows.Forms.Control+ThreadMethodEntry objects named "caller". I see that it is involved

C# WeakReference object is NULL in finalizer although still strongly referenced

懵懂的女人 提交于 2019-12-18 04:23:17
问题 Hi I have code here where I don't understand why I hit the breakpoint (see comment). Is this a Microsoft bug of something I don't know or I don't understand properly ? The code was tested in Debug but I think it should not changes anything. Note: You can test the code directly in a console app. JUST FOR INFORMATION... following supercat answer, I fixed my code with proposed solution and it works nicely :-) !!! The bad thing is the usage of a static dict and the performance the goes with it

Java Finalize method call when close the application

廉价感情. 提交于 2019-12-17 20:54:34
问题 I have question regarding the finalize method. If I have many classes with many inheritances, how can I call all finalize methods when the application closing? 回答1: System.runFinalizersOnExit(true) , but note that it's deprecated. If you're relying on this sort of thing you're already doing something wrong basically. 回答2: finalize() methods do not run on application exit. The recommended approach is to use a shutdown hook. e.g. Runtime.getRuntime().addShutdownHook(new Thread() { public void