object-lifetime

MEF keeps reference of NonShared IDisposable parts, not allowing them to be collected by GC

浪尽此生 提交于 2019-11-27 02:15:58
问题 I've encountered somewhat of a problem in MEF's part lifetime which causes memory leaks in my Prism application. My application exports views and viewmodels with the PartCreationPolicy being set to CreationPolicy.NonShared . The views and viewmodels inherit from ViewBase and ViewModelBase respectively, which implements IDisposable . Now, since my parts implement IDisposable , a reference to them is kept by the container, which causes them to not be released by the garbage collector. According

AppDomain and MarshalByRefObject life time : how to avoid RemotingException?

喜欢而已 提交于 2019-11-26 23:56:30
问题 When a MarshalByRef object is passed from an AppDomain (1) to another (2), if you wait 6 mins before calling a method on it in the second AppDomain (2) you will get a RemotingException : System.Runtime.Remoting.RemotingException: Object [...] has been disconnected or does not exist at the server. Some documentation about this isse : http://blogs.microsoft.co.il/blogs/sasha/archive/2008/07/19/appdomains-and-remoting-life-time-service.aspx http://blogs.msdn.com/cbrumme/archive/2003/06/01/51466

Extending temporary's lifetime through rvalue data-member works with aggregate, but not with constructor, why?

被刻印的时光 ゝ 提交于 2019-11-26 23:08:42
问题 I've found the following scheme to extend a temporaries lifetime works, I don't know if it should, but it does. struct S { std::vector<int>&& vec; }; int main() { S s1{std::vector<int>(5)}; // construct with temporary std::cout << s1.vec[0] << '\n'; // fine, temporary is alive } However, when S is given an explicit value constructor it is no longer an aggregate, and this scheme fails with an invalid read on s1.vec[0] struct S { std::vector<int>&& vec; S(std::vector<int>&& v) : vec{std::move(v

Invoking virtual method in constructor: difference between Java and C++

不问归期 提交于 2019-11-26 22:48:37
问题 In Java: class Base { public Base() { System.out.println("Base::Base()"); virt(); } void virt() { System.out.println("Base::virt()"); } } class Derived extends Base { public Derived() { System.out.println("Derived::Derived()"); virt(); } void virt() { System.out.println("Derived::virt()"); } } public class Main { public static void main(String[] args) { new Derived(); } } This will output Base::Base() Derived::virt() Derived::Derived() Derived::virt() However, in C++ the result is different:

About binding a const reference to a sub-object of a temporary

那年仲夏 提交于 2019-11-26 22:13:20
问题 With code like #include <iostream> struct P { int x; P(int x) : x(x) {} ~P() { std::cout << "~P()\n"; } }; int main() { auto const& x = P{10}.x; std::cout << "extract\n"; } GCC prints ~P() extract , indicating that the temporary's lifetime is not extended by the reference. By contrast, Clang (IMO correctly) extends the lifetime of the temporary to the lifetime of the reference x and the destructor will be therefore called after the output in main . Note that GCC suddenly shows Clang's

Best practice to do nested TRY / FINALLY statement

非 Y 不嫁゛ 提交于 2019-11-26 19:15:35
问题 Hi What is the best way to do nested try & finally statements in delphi? var cds1 : TClientDataSet; cds2 : TClientDataSet; cds3 : TClientDataSet; cds4 : TClientDataSet; begin cds1 := TClientDataSet.Create(application ); try cds2 := TClientDataSet.Create(application ); try cds3 := TClientDataSet.Create(application ); try cds4 := TClientDataSet.Create(application ); try /////////////////////////////////////////////////////////////////////// /// DO WHAT NEEDS TO BE DONE /////////////////////////

Spurious warning about binding temporary to reference member in constructor

蹲街弑〆低调 提交于 2019-11-26 18:25:31
问题 I understand that if a temporary is bound to a reference member in the constructor's initializer list, the object will be destroyed as the constructor returns. However , consider the following code: #include <functional> #include <iostream> using callback_func = std::function<int(void)>; int func(const callback_func& callback) { struct wrapper { const callback_func& w_cb; wrapper(const callback_func& cb) : w_cb {cb} { } int call() { return this->w_cb() + this->w_cb(); } }; wrapper wrp

C# Thread object lifetime

瘦欲@ 提交于 2019-11-26 18:19:55
问题 Suppose I have a code as follows: int Main() { if (true) { new Thread(()=> { doSomeLengthyOperation(); }).Start(); } while (true) { //do nothing } } There are 2 threads, I'm going to call the Main thread the thread that is executing the Main() function, and the thread being new'ed up inside the "if" test as Thread A. My question is, when does Thread A get destroyed? Will doSomeLenghtyOperation() be able to run into completion? Since there are no references pointing at Thread A, will it be

Why is PerThreadLifetimeManager used in this example?

我的梦境 提交于 2019-11-26 17:51:32
I am following the example linked to below for setting up unity to work with my service layer. My project is setup very similar to the one in this article and I understand everything except why exactly is PerThreadLifetimeManager used when registering the service dependency. Keep in mind I am also using a generic repository and unitofwork that is being used in my service layer as well. Most unity examples use the default(transient) lifetime manager, and since my setup is similar to the one below I'm wondering why I should use the PerThreadLifeimeManager? I am using an ASP.NET web forms project

call to pure virtual function from base class constructor

与世无争的帅哥 提交于 2019-11-26 12:26:03
问题 I have a base class MyBase that contains a pure virtual function: void PrintStartMessage() = 0 I want each derived class to call it in their constructor then I put it in base class( MyBase ) constructor class MyBase { public: virtual void PrintStartMessage() =0; MyBase() { PrintStartMessage(); } }; class Derived:public MyBase { public: void PrintStartMessage(){ } }; void main() { Derived derived; } but I get a linker error. this is error message : 1>------ Build started: Project: s1,