O'Reilly logo

Professional C# 6 and .NET Core 1.0 by Christian Nagel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

5 Managed and Unmanaged Resources

What’s In This Chapter?

  • Allocating space on the stack and heap at runtime
  • Garbage collection
  • Releasing unmanaged resources using destructors and the System.IDisposable interface
  • The syntax for using pointers in C#
  • Using pointers to implement high-performance stack-based arrays
  • Platform Invoke to access native APIs

Wrox.com Code Downloads for This Chapter

The wrox.com code downloads for this chapter are found at www.wrox.com/go/professionalcsharp6 on the Download Code tab. The code for this chapter is divided into the following major examples:

  • PointerPlayground
  • PointerPlayground2
  • QuickArray
  • PlatformInvokeSample

Resources

Resources is an overloaded term. One use of the term resources you can find with localization. With localization, resources are used to translate text and images. Based on the user’s culture, the correct resource is loaded. (This is discussed in Chapter 28, “Localization.”) Another use of the term resources you can read in this chapter. Here, resources are used with a different topic: using managed and unmanaged resources—objects that are stored on the managed or the native heap. Although the garbage collector frees up managed objects that are stored in the managed heap, it isn’t responsible for the objects in the native heap. You have to free them on your own.

When you use a managed environment, you can easily be misled to not pay attention to memory management because the garbage collector (GC) deals with that anyway. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required