Interface MemoryContext

All Superinterfaces:
Lifespan

public interface MemoryContext extends Lifespan
A PostgreSQL MemoryContext, which is usable as a PL/Java Lifespan to scope the lifetimes of PL/Java objects (as when they depend on native memory allocated in the underlying context).

The MemoryContext API in PostgreSQL is described here.

Static getters for the globally known contexts are spelled and capitalized as they are in PostgreSQL.

  • Field Details

    • TopMemoryContext

      static final MemoryContext TopMemoryContext
      The top level of the context tree, of which every other context is a descendant.

      Used as described here.

  • Method Details

    • CurrentMemoryContext

      static MemoryContext CurrentMemoryContext()
      The "current" memory context, which supplies all allocations made by PostgreSQL palloc and related functions that do not explicitly specify a context.

      Used as described here.

    • TopMemoryContext

      static MemoryContext TopMemoryContext()
      Getter method equivalent to the final TopMemoryContext field, for consistency with the other static getters.
    • TopTransactionContext

      static MemoryContext TopTransactionContext()
      Holds everything that lives until end of the top-level transaction.

      Can be appropriate when a specification, for example JDBC, provides that an object should remain valid for the life of the transaction.

      Uses are described here.

    • CurTransactionContext

      static MemoryContext CurTransactionContext()
      The same as TopTransactionContext when in a top-level transaction, but different in subtransactions (such as those associated with PL/Java savepoints).

      Used as described here.

    • PortalContext

      static MemoryContext PortalContext()
      Context of the currently active execution portal.

      Used as described here.

    • ErrorContext

      static MemoryContext ErrorContext()
      A permanent context switched into for error recovery processing.

      Used as described here.

    • JavaMemoryContext

      static MemoryContext JavaMemoryContext()
      A long-lived, never-reset context created by PL/Java as a child of TopMemoryContext.

      Perhaps useful for PL/Java-related allocations that will be long-lived, or managed only from the Java side, as a way of accounting for them separately, as opposed to just putting them in TopMemoryContext. It hasn't been used consistently even in the historical PL/Java code base, and should perhaps be a candidate for deprecation (or for a thorough code review to establish firmer guidelines for its use).

    • UpperMemoryContext

      static MemoryContext UpperMemoryContext()
      The "upper executor" memory context (that is, the context on entry, prior to any use of SPI) associated with the current (innermost) PL/Java function invocation.

      This is "precisely the right context for a value returned" from a function that uses SPI, as described here.