When dealing with memory leaks, you must be very careful, because every step in your application is important.
For beginners, every cycle you have can lead to an increase in memory. Try to reverse the use of loops to work with a dictionary and a hash table, it will cost you โnot on orderโ data, because it compares hash codes, but I donโt think you need a certain order for your data in games.
Explanation: Each array list that you have, if you know the exact size of your array, use an ArrayList. If you use a list, switch it to a dictionary if the list type is known to you or a Hash Table if not. this way, you can get key value information that is faster and improves performance.
Secondly, try using the Using syntax when you create a new object, this will help you implement the iDisposable interface to delete objects more efficiently.
Third, protect your code from box variables as much as you can! boxing means the process of storing the type of value on the heap, not on the stack, so on the stack you only have a link to the location of the variable.
Fourth, use tools to monitor your code and check for possible memory leaks in your applications. There are many tools besides the profiler, so just find it and you will find something that will help you.
source share