クラス x が y.create(new z) に移動して y を呼び出す場合、z obj は x のスタックと y のスタックで作成されますか? これは、ref や ptr ではなく、値で渡していることを前提としています。
2 に答える
いくつかのこと:
The stack/heap is on the process (application) level, not at an object level. The entire application shares one stack (at least in the context of your question), no matter how many objects it is using.
Unless the "z" in your example is a value type (like a struct), it won't ever fully reside on the stack. If "z" is a class, then it "lives" on the heap, with only a reference to it on the stack.
You really should read this short explanation from Jon Skeet - http://www.yoda.arachsys.com/csharp/memory.html - especially "A worked example" towards the bottom.
オブジェクト z は、アプリケーションに割り当てられたメモリに作成されます。new を使用してオブジェクトを作成する場合、各関数には独自のメモリ領域がありません。
このページのコンテンツを読むことをお勧めします。確かに、時々役立つと思います (つまり、物事が混乱した場合)。