In the both Ocarina of Time and Majora's Mask, it is possible to clone actors relatively easy due to how the game engine works.
There are two files that are important to actor cloning, scene and room (sometimes called map) files.
Scene files define most "global" data for a specific location of in a game (ex. Inside the Deku Tree, Hyrule Field, Zora's Domain...). Most important to this trick, a scene file contains the majority of the collision for the entire area, regardless of what room is loaded.
Room files contain the graphical data and the actor lists (i.e. the collection of objects and NPCs) for a given area. They give the developers the ability to segment an area, reducing the render load and memory requirements for large areas like dungeons. Every scene is represented by one or more room files. It's only when a scene has 2 or more room files that we can clone actors.
Under normal circumstances, only one room file is loaded at a time. However, if you hover into the space of a previous room (possible because the scene, not the room, contains the collision), and walked back in bounds through the room's loading trigger, you will load additional copies of that room's actors.
This can be used in several areas to clone certain NPCs. For example, this can be done in the Lost Woods to clone the Skull Kid that you trade the Skull Mask to, allowing you to obtain several extra heart containers.
Actor duplication is limited by either the available memory of the system, or the limited processing power available. You can generally clone a set of actors more times if there are fewer of them in an area.
All extra clones will disappear by entering a different room in the scene normally, falling out of bounds, or going to a different area, with one exception. The light beams in Ganon's Castle have a glitch where they are never unloaded naturally by the game engine, and thus duplicate on their own whenever you re-enter the main room. Falling out of bounds or going into a different area will remove duplicates of this actor.