A method for managing memory for an application (214, 314, 404) executing in a managed runtime (216, 628) using a computer, wherein the computer performs actions, including: when at least one thread of a plurality of threads executes a native code call during the execution of the application in a managed code environment, further actions are performed by the managed runtime (216, 628), including: determining at least one characteristic of the native code call based in part on configuration information that is associated with a target platform when the application (214, 314, 404) is executing; when the at least one characteristic of the native code call indicates that a duration of the native code call is expected to exceed a defined duration threshold, updating thread state information for the at least one thread to indicate that the at least one thread is executing in an unmanaged code environment, wherein the thread state information is state information for the threads known to the managed runtime (216, 628); and when the native code call completes, updating the thread state information for the at least one thread to indicate that the at least one thread is executing in the managed code environment; and when a garbage collection event occurs, further actions are performed, including: updating the thread state information for each of the plurality of threads to communicate a suspend request to the plurality of threads; then waiting for each thread of the plurality of threads that is executing in the managed code environment to become safe for garbage collection; and when each thread in the managed code environment is safe for garbage collection, executing one or more garbage collection actions to manage the memory for the application (214, 314, 404); and if the duration of the native code call is expected to exceed the defined duration threshold, saving garbage collection data for the at least one thread, updating the thread state information to indicate that the at least one thread is safe for garbage collection, and performing the one or more garbage collection actions without having to wait for the native code call to finish. when at least one thread of a plurality of threads executes a native code call during the execution of the application in a managed code environment, further actions are performed by the managed runtime (216, 628), including: determining at least one characteristic of the native code call based in part on configuration information that is associated with a target platform when the application (214, 314, 404) is executing; when the at least one characteristic of the native code call indicates that a duration of the native code call is expected to exceed a defined duration threshold, updating thread state information for the at least one thread to indicate that the at least one thread is executing in an unmanaged code environment, wherein the thread state information is state information for the threads known to the managed runtime (216, 628); and when the native code call completes, updating the thread state information for the at least one thread to indicate that the at least one thread is executing in the managed code environment; and determining at least one characteristic of the native code call based in part on configuration information that is associated with a target platform when the application (214, 314, 404) is executing; when the at least one characteristic of the native code call indicates that a duration of the native code call is expected to exceed a defined duration threshold, updating thread state information for the at least one thread to indicate that the at least one thread is executing in an unmanaged code environment, wherein the thread state information is state information for the threads known to the managed runtime (216, 628); and when the native code call completes, updating the thread state information for the at least one thread to indicate that the at least one thread is executing in the managed code environment; and when a garbage collection event occurs, further actions are performed, including: updating the thread state information for each of the plurality of threads to communicate a suspend request to the plurality of threads; then waiting for each thread of the plurality of threads that is executing in the managed code environment to become safe for garbage collection; and when each thread in the managed code environment is safe for garbage collection, executing one or more garbage collection actions to manage the memory for the application (214, 314, 404); and updating the thread state information for each of the plurality of threads to communicate a suspend request to the plurality of threads; then waiting for each thread of the plurality of threads that is executing in the managed code environment to become safe for garbage collection; and when each thread in the managed code environment is safe for garbage collection, executing one or more garbage collection actions to manage the memory for the application (214, 314, 404); and if the duration of the native code call is expected to exceed the defined duration threshold, saving garbage collection data for the at least one thread, updating the thread state information to indicate that the at least one thread is safe for garbage collection, and performing the one or more garbage collection actions without having to wait for the native code call to finish.