Click here to Skip to main content
16,007,277 members
Home / Discussions / C#
   

C#

 
GeneralRe: help for newbe Pin
ChrisKo4-Dec-07 8:03
ChrisKo4-Dec-07 8:03 
QuestionHow to delete a pointer. Pin
daavena4-Dec-07 7:24
daavena4-Dec-07 7:24 
AnswerRe: How to delete a pointer. Pin
Dave Kreskowiak4-Dec-07 7:46
mveDave Kreskowiak4-Dec-07 7:46 
GeneralRe: How to delete a pointer. Pin
daavena4-Dec-07 8:24
daavena4-Dec-07 8:24 
GeneralRe: How to delete a pointer. Pin
Dave Kreskowiak4-Dec-07 10:38
mveDave Kreskowiak4-Dec-07 10:38 
AnswerRe: How to delete a pointer. Pin
Anthony Mushrow4-Dec-07 7:47
professionalAnthony Mushrow4-Dec-07 7:47 
GeneralRe: How to delete a pointer. Pin
daavena4-Dec-07 7:59
daavena4-Dec-07 7:59 
GeneralRe: How to delete a pointer. Pin
Colin Angus Mackay4-Dec-07 10:10
Colin Angus Mackay4-Dec-07 10:10 
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 <a href="http://msdn2.microsoft.com/en-us/library/f58wzh21(VS.80).aspx">fixed</a>[<a href="http://msdn2.microsoft.com/en-us/library/f58wzh21(VS.80).aspx" target="_blank" title="New Window">^</a>] 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 the IDisposable 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


GeneralRe: How to delete a pointer. Pin
daavena4-Dec-07 8:01
daavena4-Dec-07 8:01 
AnswerRe: How to delete a pointer. Pin
PIEBALDconsult4-Dec-07 8:42
mvePIEBALDconsult4-Dec-07 8:42 
GeneralHi I again Pin
wasimsharp4-Dec-07 4:26
wasimsharp4-Dec-07 4:26 
GeneralRe: Hi I again Pin
Luc Pattyn4-Dec-07 5:04
sitebuilderLuc Pattyn4-Dec-07 5:04 
QuestionHow to make viewstate work for inactive textbox? Pin
bochno4-Dec-07 4:07
bochno4-Dec-07 4:07 
GeneralRe: How to make viewstate work for inactive textbox? Pin
bochno4-Dec-07 21:13
bochno4-Dec-07 21:13 
GeneralNullReferanceException when using a callback and Invoke Pin
Member 38482694-Dec-07 3:36
Member 38482694-Dec-07 3:36 
GeneralRe: NullReferanceException when using a callback and Invoke Pin
J4amieC4-Dec-07 5:39
J4amieC4-Dec-07 5:39 
QuestionWhat this error ? Pin
E_Gold4-Dec-07 3:05
E_Gold4-Dec-07 3:05 
AnswerRe: What this error ? Pin
Judah Gabriel Himango4-Dec-07 7:52
sponsorJudah Gabriel Himango4-Dec-07 7:52 
GeneralTCP/IP (Server To Server) Pin
half-life4-Dec-07 3:02
half-life4-Dec-07 3:02 
Questioninvalid report file path of crystal Report Pin
infi_20074-Dec-07 2:40
infi_20074-Dec-07 2:40 
GeneralCreating Website in SharePoint using C#/ASP.NET Pin
md Nazeem4-Dec-07 2:32
md Nazeem4-Dec-07 2:32 
GeneralC# Interop problem under Vista Pin
Stevo Z4-Dec-07 2:22
Stevo Z4-Dec-07 2:22 
GeneralHelp on changing color of a listbox item Pin
Kyle Maldonado4-Dec-07 2:12
Kyle Maldonado4-Dec-07 2:12 
QuestionHow to programmatically change the icon of the application .exe Pin
Member 47491754-Dec-07 2:06
Member 47491754-Dec-07 2:06 
AnswerRe: How to programmatically change the icon of the application .exe Pin
PIEBALDconsult4-Dec-07 3:40
mvePIEBALDconsult4-Dec-07 3:40 

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.