object-lifetime

What is the best way to do nested TRY AND FINALLY statement in Delphi

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 := TClientD...

A Question On Smart Pointers and Their Inevitable Indeterminism

I've been extensively using smart pointers (boost::shared_ptr to be exact) in my projects for the last two years. I understand and appreciate their benefits and I generally like them a lot. But the more I use them, the more I miss the deterministic behavior of C++ with regarding to memory management and RAII that I seem to like in a prog...

MVC Object Instances or Static classes?

I am confused as to when to create object instances or Static Helper classes. For example, if I call a method to update a data model and submit to database, i create an instance of the DataContext. What is the lifetime of that Datacontext and is it ok to create new instances every time there needs to be a new data updates? In my contro...

.NET - Finalizers and exit(0)

I have a .NET C# / C++ app which uses a call to exit(0) (from <stdlib.h>) in a thread in order to terminate. The strange part is, under some circumstances, the finalizers of the managed objects are called right after the call to exit, and in other circumstances, they are not called at all. The circumstances are pretty deterministic - t...

What is the lifetime and validity of C++ iterators ?

I'm planning to implement a list of Things in C++ where elements might be removed out of order. I don't expect that i'll need any kind of random access (i just need to sweep the list periodically), and the order of items isn't important either. So I thought of std::list<Thing*> with this->position = insert(lst.end(), thing) should do th...

What other IoC containers have an IInitializable like feature?

I've been using Castle Windsor in my previous project and I liked it a lot. For my current project I'm looking to use a different IoC container. Castle Windsor hasn't had any new releases since 2007 and is still not at version 1.0 so it is hard to justify using it in a commercial environment. One of the things I like about Castle Windso...

When does a mutable state value freed from heap?

On F# WikiBook under Encapsulating Mutable State section, there is a following code snippet. > let incr = let counter = ref 0 fun () -> counter := !counter + 1 !counter;; val incr : (unit -> int) > incr();; val it : int = 1 > incr();; val it : int = 2 > incr();; val it : int = 3 At first, it seemed easy eno...

What are the advantages of using a concept like IStartable?

Instead of using an interface like this: public interface IStartable { void Start(); void Stop(); } I usually just make the constructor of an object run the Start() code, and implement IDisposable so that the dispose method runs the Stop() code. Is it just a matter of style? Or am I missing something important by not having s...

Detecting when an NSView is dealloc'ed

Is there any way to detect when an NSView will be dealloc'ed? The reason is, I have some simple delegates (such as an NSTextField delegate that handles -control:textView:doCommandBySelector: to allow the return/tab keys to be entered). I'd like to just stick this delegate object in the nib, wire up the NSTextField's delegate connection...

What are the effects of failing to close/dispose Powershell Runspace objects before process termination?

Given an application that maintains a singleton instance of a Runspace object (from System.Management.Automation.Runspaces) for the lifetime of the application, what are the potential side effects of failing to dispose of the Runspace before the application is terminated? The design rationale I have been presented with is that memory/ha...

Can I make a C# object's lifetime depend on another object?

I have an object (Delegate) which needs to stay alive (not garbage collected) while another object (TargetObject) is alive. I want Delegate to be garbage collected when TargetObject is collected (or at least available for collection). The difficulty is that I don't want to need to reference Delegate from TargetObject since I want it to...

Should this C++ temporary binding to reference member be illegal?

Hello, My question (which will follow after this, sorry about the long intro, the question is down there in bold) is originally inspired by Item 23 in Herb Sutters Exceptional C++ where we find something like this: <snip> ... int main() { GenericTableAlgorithm a( "Customer", MyWorker() ); a.Process(); } with class GenericT...

Lifetime management with Google Guice

Is there a recommended pattern for shutting down / closing objects created with Guice? The lifecycle I'm aiming for is: Prepare a Guice Module Create an injector Use the injector through your code to obtain objects (injector.getInstance(Foo.class)) ... Close any resources held by said objects (file handles, TCP connections, etc...). I...

Linq to Sql DataContext life cycle in a WCF service

Hi, I have a service exposed via WCF. The service exposes several methods that talk to the database through a Linq to SQL datacontext. The datacontext is bound to the CallContext. All of this is working as it should but I can't figure out the proper place to dispose the Linq to SQL datacontext. Please help. ...

Problem with storing COM pointers in global singleton object

Background The application I am working with has several COM DLLs. One of the COM DLLs has a global singleton object, which stores pointers to COM interfaces in other DLLs. Because it is a global singleton object, I have employed the lazy initialization idiom because it is possible that the interface I am trying to get a pointer to ex...

Lifetime management in mvc turbine?

How can I manage the lifetime of my services in mvc turbine (using Unity)? I have an ISearchService implementation LuceneSearchService that takes an IConfigurationService and ILoggerService. Currently my searchservice registration looks like this: public class SearchServiceRegistration: IServiceRegistration { public void Registe...

Why is this instance initiated by Unity not a singleton?

in my asp.net-mvc application I have a statis MvcApplication that calls a static CreateContainer() method. In this method I create my unity ioc container: private static IUnityContainer CreateContainer() { var container = new UnityContainer(); container.RegisterType<IConfigurationService, ConfigFile>(); container.RegisterTy...

__del__ method being called in python when it is not expected

Hello, I am new to python and have been working through the examples in Swaroop CH's "A Byte of Python". I am seeing some behavior with the __del__ method that is puzzling me. Basically, if I run the following script (in Python 2.6.2) class Person4: '''Represents a person''' population = 0 def __init__(self, name): ...

boost signals - How control lifetime of objects sent to subscribers? Smart pointers?

I am using boost::signals2 under Red Hat Enterprise Linux 5.3. My signal creates an object copy and sends it's pointer to subscribers. This was implemented for thread safety to prevent the worker thread from updating a string property on the object at the same time it is being read ( perhaps I should revisit the use of locks? ). Anywa...

Singleton factory, sort of....

Sorry if this has been answered elsewhere... I have found a lot of posts on similar things but not the same. I want to ensure that only one instance of an object exists at a time BUT I don't want that object to be retained past its natural life-cycle, as it might be with the Singleton pattern. I am writing some code where processing o...