Mac Developer Library

Developer

OSObject Class Reference

Options
Deployment Target:

On This Page
Language:

OSObject

OSObject is the concrete root class of the Libkern and I/O Kit C++ class hierarchy. More...

Inheritance


Not Applicable

Conforms To


Not Applicable

Import Statement


Not Applicable @import Kernel;

Availability


Available in OS X v10.0 and later.
  • Deallocates/releases resources held by the object.

    Declaration

    C++

    virtual void free();

    Discussion

    Classes derived from OSObject should override this function to deallocate or release all dynamic resources held by the instance, then call the superclass's implementation.

    Caution:

    1. You can not assume that you have completed initialization before free is called, so be very careful in your implementation.

    2. OSObject's implementation performs the C++ delete of the instance, so be sure that you call the superclass implementation last in your implementation.

    3. free must not fail; all resources must be deallocated or released on completion.

    Import Statement

  • Returns the reference count of the object.

    Declaration

    C++

    virtual int getRetainCount() const;

    Return Value

    The reference count of the object.

    Import Statement

  • Initializes a newly-allocated object.

    Declaration

    C++

    virtual bool init();

    Return Value

    true on success, false on failure.

    Discussion

    Classes derived from OSObject must override the primary init method of their parent. In general most implementations call ::init() before doing local initialisation. If the superclass call fails then return false immediately. If the subclass encounters a failure then it should return false.

    Import Statement

  • Frees the memory of the object itself.

    Declaration

    C++

    static void operator delete( void *mem, size_tsize);

    Parameters

    mem

    A pointer to the object's memory.

    size

    The size of the object's block of memory.

    Discussion

    Never use delete on objects derived from OSObject; use release instead.

    Import Statement

  • Allocates memory for an instance of the class.

    Declaration

    C++

    static void * operator new( size_tsize);

    Parameters

    size

    The number of bytes to allocate

    Return Value

    A pointer to block of memory if available, NULL otherwise.

    Import Statement

  • Releases a reference to the object, freeing it immediately if the reference count drops to zero.

    Declaration

    C++

    virtual void release() const;

    Discussion

    This function decrements the reference count of the receiver by 1. If the reference count drops to zero, the object is immediately freed using free.

    Import Statement

  • Releases a reference to an object, freeing it immediately if the reference count drops below the specified threshold.

    Declaration

    C++

    virtual void release( intfreeWhen) const;

    Parameters

    freeWhen

    If decrementing the reference count makes it >= freeWhen, the object is immediately freed.

    Discussion

    If the receiver has freeWhen or fewer references after its reference count is decremented, it is immediately freed.

    This version of release can be used to break certain retain cycles in object graphs. In general, however, it should be avoided.

    Import Statement

  • Retains a reference to the object.

    Declaration

    C++

    virtual void retain() const;

    Discussion

    This function increments the reference count of the receiver by 1. If you need to maintain a reference to an object outside the context in which you received it, you should always retain it immediately.

    Import Statement

  • Overridden by subclasses to archive the receiver into the provided OSSerialize object.

    Declaration

    C++

    virtual bool serialize( OSSerialize *serializer) const;

    Parameters

    serializer

    The OSSerialize object.

    Return Value

    true if serialization succeeds, false if not.

    Discussion

    OSObject's implementation writes a string indicating that the class of the object receiving the function call is not serializable. Subclasses that can meaningfully encode themselves in I/O Kit-style property list XML can override this function to do so. See OSSerialize for more information.

    Import Statement

  • Releases a tagged reference to an object, freeing it immediately if the reference count drops to zero.

    Declaration

    C++

    virtual void taggedRelease( const void *tag = 0) const;

    Parameters

    tag

    Used for tracking collection references.

    Discussion

    Kernel extensions should not use this function. It is for use by OSCollection and subclasses to track inclusion in collections.

    Import Statement

  • Releases a tagged reference to an object, freeing it immediately if the reference count drops below the specified threshold.

    Declaration

    C++

    virtual void taggedRelease( const void *tag, const intfreeWhen) const;

    Parameters

    tag

    Used for tracking collection references.

    freeWhen

    If decrementing the reference count makes it >= freeWhen, the object is immediately freed.

    Discussion

    Kernel extensions should not use this function. It is for use by OSCollection and subclasses to track inclusion in collections.

    If the receiver has freeWhen or fewer references after its reference count is decremented, it is immediately freed.

    This version of release can be used to break certain retain cycles in object graphs. In general, however, it should be avoided.

    Import Statement

  • Retains a reference to the object with an optional tag used for reference-tracking.

    Declaration

    C++

    virtual void taggedRetain( const void *tag = 0) const;

    Parameters

    tag

    Used for tracking collection references.

    Discussion

    Kernel extensions should not use this function. It is for use by OSCollection and subclasses to track inclusion in collections.

    If you need to maintain a reference to an object outside the context in which you received it, you should always retain it immediately.

    Import Statement