1. A method for handling a pointer while executing program code, comprising: by an electronic device: encountering a pointer in the program code that points to an unspecified address space, wherein the pointer includes metadata that indicates one or more address spaces to which the pointer may point; and collecting information about one or more runtime conditions based on at least one of operations that use the pointer and operations related to operations that use the pointer that do not directly use the pointer, wherein the information indicates at least one candidate address space to which the pointer may point; and using the collected information and the metadata to determine an address space to which the pointer points.