Best practices for garbage collection?

I've noticed the longer my app runs the more memory it has allocated (judging by the Task Manager anyway). So time to look for leaks.

Wondering what are best practices for memory management?

Is it safe to assume that things that go out of scope will clean up? I use the WWW object to get xml data and load remote pictures (from a video camera) quite often, do I need to worry about those bits? Do I need to destroy a texture, for example, before I load a new one, or vice versa?

Any tips welcome.

Unity objects like textures are not garbage collected and need to be manually destroyed. Currently with Unity 2.6, there's no way to actually free the memory aside from loading a new level. Unity iPhone has Application.GarbageCollectUnusedAssets, which can be called at any time. I believe this functionality is available across the board in Unity 3, under a different name.

Mono objects and variables are handled automatically by Mono's garbage collection.

Try the advices here:

http://msdn.microsoft.com/en-us/library/0xy59wtx.aspx

and here:

http://msdn.microsoft.com/en-us/library/ms973837.aspx

Same principles apply in Unity.

The most basic collection algorithm “mark - Clear all objects that need to be recycled (Mark-Sweep) algorithm, such as its name, the algorithm is divided into the” mark “and” clear "in two stages: First, mark, mark completedafter unification recycling out all objects are marked, mark fact, the first one about the object marker determine basic introduction over. We say it is the most basic collection algorithm, and the subsequent collection algorithms are based on this line of thinking, and to improve its shortcomings. Its main disadvantage of the two: a question of efficiency, marking and clearance process efficiency is not high; another space, space debris will produce a large number of non-contiguous memory fragmentation, too much may cause the flag is cleared, when can not find enough contiguous memory in the program need to allocate a large object after running had to trigger another garbage collection action in advance.