I guess so. This is only viable if you have enough time for garbage collection.
Also the GC is only triggered on a memory allocation. It doesn't run in a background thread or anything like that. So if the GC fails, then the allocation of memory fails (as I understand it) which means your scenario would be caught early.
Does this mean that they use different heaps?