Click here to Skip to main content
15,920,438 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
GeneralRe: What makes a class IDisposable? [modified] Pin
iddqd51513-Aug-07 9:43
iddqd51513-Aug-07 9:43 
GeneralRe: What makes a class IDisposable? Pin
Mark Salsbery13-Aug-07 9:51
Mark Salsbery13-Aug-07 9:51 
GeneralRe: What makes a class IDisposable? Pin
iddqd51513-Aug-07 9:55
iddqd51513-Aug-07 9:55 
GeneralRe: What makes a class IDisposable? Pin
Luc Pattyn13-Aug-07 7:00
sitebuilderLuc Pattyn13-Aug-07 7:00 
GeneralRe: What makes a class IDisposable? Pin
Mark Salsbery12-Aug-07 10:06
Mark Salsbery12-Aug-07 10:06 
GeneralRe: What makes a class IDisposable? Pin
George L. Jackson14-Aug-07 3:48
George L. Jackson14-Aug-07 3:48 
GeneralRe: What makes a class IDisposable? Pin
Mark Salsbery14-Aug-07 5:10
Mark Salsbery14-Aug-07 5:10 
GeneralRe: What makes a class IDisposable? Pin
Mark Salsbery13-Aug-07 4:53
Mark Salsbery13-Aug-07 4:53 
hmm...my Sunday morning reply made no sense - I'll take another crack at it.

What I meant to say was...

If you have unmanaged resources in a managed class then you'll need a way to
free them, as always. 

You could just cleanup your native resources in the destructor BUT the destructor
won't be called unless you explicitly call it (using delete or calling it directly). 
Having to do THAT would be counterintuitive Smile | :)

To ensure your native object created with new gets deleted, you should implement
a destructor AND a finalizer in its managed owner class - that's what Nish's smart pointer
class does for you.
That way you don't have to explicitly destruct your managed object.  If it is left
for the GC to cleanup, the GC will call the finalizer (NOT the destructor!)...
// Using this pattern will insure native/unmanaged objects are cleaned up in all cases

ref class MyRefClass
{
   int *NativeIntArray;
public:
   MyRefClass()  {NativeIntArray = new int[400];} // Constructor
   ~MyRefClass()  {this->!MyRefClass();}          // Destructor - cleanup managed objects / call finalizer
   !MyRefClass()  {delete[] NativeIntArray;}      // Finalizer - cleanup native objects
}
Cheers,
Mark



Mark Salsbery
Microsoft MVP - Visual C++

Java | [Coffee]

QuestionControl within a control help please [modified] Pin
Xpnctoc11-Aug-07 6:54
Xpnctoc11-Aug-07 6:54 
Questionassignment vs default ctor Pin
swjam11-Aug-07 5:19
swjam11-Aug-07 5:19 
AnswerRe: assignment vs default ctor Pin
Mark Salsbery11-Aug-07 6:55
Mark Salsbery11-Aug-07 6:55 
Questionoperator++(int) Pin
swjam11-Aug-07 4:58
swjam11-Aug-07 4:58 
AnswerRe: operator++(int) Pin
Mark Salsbery11-Aug-07 6:58
Mark Salsbery11-Aug-07 6:58 
AnswerRe: operator++(int) Pin
BadKarma11-Aug-07 23:48
BadKarma11-Aug-07 23:48 
QuestionRTTI dynamic_cast Pin
swjam11-Aug-07 0:45
swjam11-Aug-07 0:45 
AnswerRe: RTTI dynamic_cast [modified] Pin
swjam11-Aug-07 0:51
swjam11-Aug-07 0:51 
QuestionIn C++/CLI, What has replaced LOGFONT and TEXTMETRIC? Pin
BuckBrown10-Aug-07 12:05
BuckBrown10-Aug-07 12:05 
QuestionHow do you get screen graphics into Document? Pin
BuckBrown9-Aug-07 9:54
BuckBrown9-Aug-07 9:54 
AnswerRe: How do you get screen graphics into Document? Pin
Luc Pattyn9-Aug-07 10:40
sitebuilderLuc Pattyn9-Aug-07 10:40 
GeneralRe: How do you get screen graphics into Document? Pin
BuckBrown9-Aug-07 11:05
BuckBrown9-Aug-07 11:05 
GeneralRe: How do you get screen graphics into Document? Pin
Luc Pattyn9-Aug-07 11:18
sitebuilderLuc Pattyn9-Aug-07 11:18 
GeneralRe: How do you get screen graphics into Document? Pin
BuckBrown9-Aug-07 11:40
BuckBrown9-Aug-07 11:40 
GeneralRe: How do you get screen graphics into Document? Pin
Luc Pattyn9-Aug-07 11:42
sitebuilderLuc Pattyn9-Aug-07 11:42 
Questiondirectx Pin
saisp8-Aug-07 18:22
saisp8-Aug-07 18:22 
Questionc++ projects Pin
Reet Dhiman7-Aug-07 23:43
Reet Dhiman7-Aug-07 23:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.