← All CPP Flashcard Decks

Memory Management & Performance Optimization Flashcards

6 cards from real CPP practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.

Read the first 6 Memory Management & Performance Optimization flashcards as text
  1. What is a dangling pointer?

    Answer: A pointer that points to freed or invalid memory

    A dangling pointer references memory that has already been freed, leading to undefined behavior if dereferenced.

  2. Which profiling technique samples the call stack at regular intervals to identify hotspots?

    Answer: Sampling profiling

    Sampling profilers periodically capture the call stack to approximate where a program spends most of its time with low overhead.

  3. What is the purpose of lazy initialization?

    Answer: Defer object creation until the first time it is actually needed

    Lazy initialization avoids expensive setup until it's necessary, improving startup time and avoiding unnecessary resource use.

  4. What causes a stack overflow error?

    Answer: Excessive recursion or very large local variables exhausting the call stack

    A stack overflow occurs when the call stack grows beyond its fixed size limit, typically due to infinite or very deep recursion.

  5. What is memory fragmentation and how does it affect performance?

    Answer: Free memory blocks scattered throughout the heap making it hard to allocate large contiguous blocks

    Heap fragmentation results in wasted memory and allocation failures even when total free memory is sufficient but not contiguous.

  6. What is memoization in the context of performance optimization?

    Answer: Caching the results of expensive function calls and returning the cached result for the same inputs

    Memoization avoids redundant computation by storing previously computed results, trading memory for speed.