The game uses an internal variable called GarryDeathCount (presumably short for Garry Death Counter) to determine whether Garry will be slain near the end of the game. Some people prefer to think of it as Mary's Hate or Damage to the Exhibits. If the counter reaches 3, Ib's Rose will not appear in the toy box and Garry will be doomed.
Unless noted, these raise the counter by 1. To avoid Garry's demise, you'll want to avoid doing these:
- Allow Garry to destroy the Manikin early on.
- In the part with 5 ropes, pull the 5th rope, dropping either a doll or a manikin head, depending on whether the manikin was destroyed earlier.
- In the part where Ib can push manikin heads off tables, push off all three, instead of just the necessary one.
- When Garry needs to get a doll out of his way, kick the doll.
- When attempting to escape from the room with the dolls, run out of time (increases count by 2). Note that if the doll was kicked earlier, the timer runs faster. In old versions of the game, the correct doll was always in the top right of the room, while in newer versions the room was changed and the correct doll is randomized.
- In an extra part of a conversation between Ib and Mary that only occurs if the counter is 0, after Mary asks "What if only two of us can escape?", tell Mary you'd leave her behind.
Generally, if you're careful with the exhibit and succeed at the timed escape, he'll survive.
Building a relationship with Garry has nothing to do with his survival. If he does survive, though, building the relationship will allow you to give him your handkerchief, resulting in the Promise of Reunion ending instead of Memory's Crannies, unless you decide not to escape the world of paintings and thus get Ib All Alone. An update added another ending which can only be taken if you've given Garry the handkerchief as well.
Finally, an update added a couple endings in which Garry and Ib give up on their escape early, which technically results in Mary not killing Garry.