# Memory crash problem

**URL:** https://discussions.unity.com/t/memory-crash-problem/494283
**Category:** Mobile
**Tags:** iOS
**Created:** [January 7, 2013, 8:52am UTC](https://discussions.unity.com/t/memory-crash-problem/494283 "2013-01-07T08:52:53Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![chishti](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/chishti/32/559697_2.png) [@chishti](https://discussions.unity.com/u/chishti)
#### Post date: [January 7, 2013, 8:52am UTC](https://discussions.unity.com/t/memory-crash-problem/494283/1 "2013-01-07T08:52:53Z")

</div>

Hi,

I am using GUI graphics to load from an external path. I include these GUI Graphics in my exported xCode project. I have to use my Character GUI avatars from external path (reason for loading externally is to include In App Purchase for new bought characters), and have to load different graphics for Ratina and Simple iPad. All other graphics like Buttons, backgrounds etc… I am using them in Resources Folder of my unity project. So only my Character graphics have to be loaded from an external path. I am using this code to load character avatars.

```auto
public Texture2D getTexture2D(string forPath) {
Texture2D tex = new Texture2D(256, 256);
tex.LoadImage(System.IO.File.ReadAllBytes(forPath));
tex.Compress(true);
return tex;
}

```

I have different type of characters, So when I load different characters 4, or 5 times in my Character loader window, application crashes.  
As I can not use Resources.UnloadAsset, because I am not loading them from resources.  
To resolve this, I tried to use GC.Collect() to release memory. I called this after every 2 times opened Character Loader. But not working.

I am interested to use Resources folder for characters but I will not be able to copy new bought characters in Resources folder when project is live.

Any idea/Solution for the problem/memory crash?

thanks

---

<div class="post-metadata">

### Author: ![xiongmaoboshi](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/xiongmaoboshi/32/241518_2.png) [@xiongmaoboshi](https://discussions.unity.com/u/xiongmaoboshi)
#### Post date: [January 7, 2013, 9:43am UTC](https://discussions.unity.com/t/memory-crash-problem/494283/2 "2013-01-07T09:43:19Z")

</div>

Hi,

[Unity - Manual: Getting started with iOS](http://docs.unity3d.com/Documentation/Manual/iphone-GettingStarted.html) states that iOS does not support DXT compression meaning the Compress() function doesn’t do anything as mentioned by [Unity - Scripting API: Texture2D.Compress](http://docs.unity3d.com/Documentation/ScriptReference/Texture2D.Compress.html). So I would try disabling it to see if it prevents the crashing.

---

<div class="post-metadata">

### Author: ![chishti](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/chishti/32/559697_2.png) [@chishti](https://discussions.unity.com/u/chishti)
#### Post date: [January 7, 2013, 11:41am UTC](https://discussions.unity.com/t/memory-crash-problem/494283/3 "2013-01-07T11:41:49Z")

</div>

no it still crashing ☹

---

<div class="post-metadata">

### Author: ![Mantas-Puida](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@Mantas-Puida](https://discussions.unity.com/u/Mantas-Puida)
#### Post date: [January 7, 2013, 8:19pm UTC](https://discussions.unity.com/t/memory-crash-problem/494283/4 "2013-01-07T20:19:10Z")

</div>

Depending on your image format loading images that way may bring excessive memory allocation overhead.  
AssetBundles loaded via WWW.LoadFromCacheOrDownload might be better solution.

---

<div class="post-metadata">

### Author: ![chishti](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/chishti/32/559697_2.png) [@chishti](https://discussions.unity.com/u/chishti)
#### Post date: [January 8, 2013, 4:33am UTC](https://discussions.unity.com/t/memory-crash-problem/494283/5 "2013-01-08T04:33:23Z")

</div>

OK today I will try that also.

My application was using a heavy use of GUIs ( like buttons, DrawTexture, GUIGroup, Label ). What I did is to optimized the code in a way so that it draws the GUIs that are view able in my custom scroll.  
Also I reduced the memory size of some of character images by decreasing its DPI/Resolution value to 30.

These two steps made difference on crash.
