How to delete a pointer.
-
What do you mean? There's nothing here to "delete". It would appear that you're comming from a C++ background and trying to use pointers the exact same you did before. C# does support pointers, but not to the extent that C++ does.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
I'm not sure that you need to, C# has that garbage collection thing. Where it clears memory that's not being used every now and then.
My current favourite word is: Bauble!
-SK Genius
-
I'm not sure that you need to, C# has that garbage collection thing. Where it clears memory that's not being used every now and then.
My current favourite word is: Bauble!
-SK Genius
-
I'm not sure that you need to, C# has that garbage collection thing. Where it clears memory that's not being used every now and then.
My current favourite word is: Bauble!
-SK Genius
-
What do you mean? There's nothing here to "delete". It would appear that you're comming from a C++ background and trying to use pointers the exact same you did before. C# does support pointers, but not to the extent that C++ does.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
It'll go out of scope.
-
C# has the garbage collection I agree with you. But I have to use usafe code. when I turn it on, wil garbage collection still work?
daavena wrote:
But I have to use usafe code. when I turn it on, wil garbage collection still work?
Yes, it will still work. However, remember it is non-deterministic. If you are using pointers into the managed heap you need to make the pointer
[fixed](http://msdn2.microsoft.com/en-us/library/f58wzh21\(VS.80\).aspx)[[^](http://msdn2.microsoft.com/en-us/library/f58wzh21\(VS.80\).aspx "New Window")]
to ensure that garbage collection does not occur on the object you have a pointer to (remember the garbage collection process will also attempt to defragment the heap, so even if the object isn't being collected it may be moved around). So, once you are finished with your object just ensure it is no longer fixed and allow the managed reference to the memory go out of scope and the garbage collector will get it. If you are encapsulating some piece of native code into a class you may want to look at theIDisposable
interface as a way of cleaning up resources when an object of that class is no longer required. This is especially important if the native code did the memory allocation rather than you allocate memory then pass it to the native code.
Upcoming FREE developer events: * Developer Day Scotland My website
-
Yeah, with pointers, unsafe code is a given. You haven't answered anyones questions about what you're trying to do with this. There is no such thing as "deleting" with a pointer in C#.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007