Re: interface programming



dummy#1 wrote:
Hi All,

I have a question.

In C#, I have auto garbage collector so I can freely do:

ICar pGenericCar = carFactory.createCar( toyotaEnum );

Without worrying about memory leaks.

in C++, how can I do the same without memory leaks?

ICar pGenericCar = carFactory.createCar( toyotaEnum ); // who will
delete this heap object since C++ interfaces have no ctor or dtor?

Are you speaking about managed or native C++?

In managed C++, the garbage collector will work exactly yhe same as in C#.

In native C++, there is no such thing as an interface, and ICar is therefore
a class or a struct. You can define a destructor on it.

Arnaud
MVP - VC


.



Relevant Pages

  • Re: interface programming
    ... I have auto garbage collector so I can freely do: ... Without worrying about memory leaks. ... there are two common patterns for interfaces: ... COM style - AddRef/Release used to manage object lifetime. ...
    (microsoft.public.vc.stl)
  • Re: netbeans or java ?
    ... > thought Java programs didn't need to worry about memory leaks because of the ... > garbage collector. ... > Is the JVM at fault for the memory leaks? ... PGP Key available from your friendly local key server ...
    (comp.lang.java.programmer)
  • Re: Memory issues
    ... with observe_malloc_free.pl in mail bottom. ... this result of memory leaks: ... 10 Mbytes data are not freed. ... I don't know much about the perl garbage collector, ...
    (comp.lang.perl.misc)
  • Re: Managed VC++ crashing in debug build caused memory leaks
    ... I was surprised to see memory leaks in our application when it crashed ... Does the garbage collector not work in debug build ... can also allocate from the native heap. ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Managed VC++ crashing in debug build caused memory leaks
    ... Ben Voigt wrote: ... I was surprised to see memory leaks in our application when it crashed ... Does the garbage collector not work in debug ... the memory leaks are an artefact of compiling in debug mode only? ...
    (microsoft.public.dotnet.languages.vc)

Quantcast