Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 938963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:42:54+00:00 2026-05-15T21:42:54+00:00

how do CLR interact with unsafe code I found various result on Google but

  • 0

how do CLR interact with unsafe code I found various result on Google but i couldn’t understand. I am also confused that is Garbage collector work on unsafe code? if yes than how?

I cant point pointer to Array,s first element
I try this code

unsafe{

  int[] a = { 4, 5 };
  int* b = a;
  }

but I got that error
Error :Cannot implicitly convert type ‘int[]’ to ‘int*’

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T21:42:54+00:00Added an answer on May 15, 2026 at 9:42 pm

    No reason why the garbage collector wouldn’t work on unsafe code. I’m assuming you’re talking about pointers to pinned objects, like:

    int[] arr = new int[100];
    unsafe
    {
         fixed (int* p = arr)
         { 
              // use p
         }
    }
    

    At the end of the block p is unaccesible anymore, so it can be safely collected.

    Now… this isn’t always true. You might pass the pointer to other functions and then exit the block (the EnumWindows family of functions come to mind where you give them a pointer to a structure and then can be done with the function you’re in, they handle the rest themselves).

    The GC.KeepAlive “function” (read hack) is used to handle this case by holding the variable in scope until you’re really done with it — that’s right, it does nothing except trick the GC into thinking you’re still using the reference.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how native code can interact with .NET code and
I am totally new to SQL Server CLR. I understand that we should use
I've got a Clr user defined type that takes a string of values sepertated
Dotnet CLR converts the language code to MSIL. While Java Code be converted to
I was reading CLR via C# and it seems that in this example, the
/clr:pure switch generates pure MSIL but it is not verifible. Native array and pointer
The CLR Profiler can also reveal which methods allocate more storage than you expected,
I have a CLR stored procedure that references an assembly created in VS 2008
In chapter eight (p189) of CLR Via C#, Jeffrey Richter states that: A Type
I have written a CLR stored procedure that is in an assembly. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.