# MrPig memory issue

**URL:** <https://forums.kodeco.com/t/mrpig-memory-issue/58317>\
**Category:** 3D iOS Games by Tutorials\
**Created:** [December 24, 2018, 10:12pm UTC](https://forums.kodeco.com/t/mrpig-memory-issue/58317 "2018-12-24T22:12:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![hemppa](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/hemppa/32/79544_2.png) [@hemppa](https://forums.kodeco.com/u/hemppa)\
**Post date:** [December 24, 2018, 10:12pm UTC](https://forums.kodeco.com/t/mrpig-memory-issue/58317/1 "2018-12-24T22:12:19Z")

</div>

It seems that every time MrPig gets hit by a bus and a new round is launched, reserved memory increases roughly by 200MB which eventually will crash the application after few rounds once reserved memory reaches approximately 1,2GB.

I tried to chase the root cause for this but was unable to understand what actually causes that +200MB increase in memory every time MrPig respawns. Can someone confirm this is a real issue or just a random bug generated by my system? I used version which is in 23-Audio, final\_bugfix folder.

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [December 25, 2018, 12:05am UTC](https://forums.kodeco.com/t/mrpig-memory-issue/58317/2 "2018-12-25T00:05:15Z")

</div>

@chrislanguage Can you please help with this when you get a chance? Thank you - much appreciated! :]

---

<div class="post-metadata">

**Author:** ![sergeydi](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/sergeydi/32/81494_2.png) [@sergeydi](https://forums.kodeco.com/u/sergeydi)\
**Post date:** [January 27, 2019, 5:53am UTC](https://forums.kodeco.com/t/mrpig-memory-issue/58317/3 "2019-01-27T05:53:57Z")

</div>

I have the same issue and in final\_bugfix version of the app too. @hemppa do you found how to solve it?

---

<div class="post-metadata">

**Author:** ![sergeydi](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/sergeydi/32/81494_2.png) [@sergeydi](https://forums.kodeco.com/u/sergeydi)\
**Post date:** [January 27, 2019, 9:06am UTC](https://forums.kodeco.com/t/mrpig-memory-issue/58317/4 "2019-01-27T09:06:53Z")

</div>

I found that memory leak issue happens even in Chapter 19 final project with code:

```
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    if game.state == .tapToPlay {
      startGame()
    } else {
        gameScene.isPaused = true
        let transition = SKTransition.doorsOpenVertical(withDuration: 1.0)
        scnView.present(splashScene, with: transition, incomingPointOfView: nil, completionHandler: {
            self.game.state = .tapToPlay
            self.setupSounds()
            self.splashScene.isPaused = false
        })
    }
  }

```

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [January 27, 2019, 12:45pm UTC](https://forums.kodeco.com/t/mrpig-memory-issue/58317/5 "2019-01-27T12:45:17Z")

</div>

@chrislanguage Do you have any feedback about this? Thank you - much appreciated! :]

---

<div class="post-metadata">

**Author:** ![sergeydi](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/sergeydi/32/81494_2.png) [@sergeydi](https://forums.kodeco.com/u/sergeydi)\
**Post date:** [January 29, 2019, 6:03am UTC](https://forums.kodeco.com/t/mrpig-memory-issue/58317/6 "2019-01-29T06:03:54Z")

</div>

I found that issue happens because of:

```
scnView.present(splashScene, with: transition, incomingPointOfView: nil, completionHandler: {
       self.game.state = .tapToPlay
       self.splashScene.isPaused = false
})

```

If to present scenes use:

```
scnView.scene = splashScene
self.game.state = .tapToPlay
self.splashScene.isPaused = false

```

No memory issue happens

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [January 29, 2019, 6:08am UTC](https://forums.kodeco.com/t/mrpig-memory-issue/58317/7 "2019-01-29T06:08:15Z")

</div>

@sergeydi Thank you for sharing your solution - much appreciated! :]

---

<div class="post-metadata">

**Author:** ![system](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@system](https://forums.kodeco.com/u/system)\
**Post date:** [June 9, 2019, 2:12pm UTC](https://forums.kodeco.com/t/mrpig-memory-issue/58317/8 "2019-06-09T14:12:20Z")

</div>

This topic was automatically closed after 166 days. New replies are no longer allowed.
