- Home /
Question by
janzdott · Aug 24, 2012 at 08:28 PM ·
arraygcgarbage collector
Changing value of an entire Array causing problems
I have a function (myFunction) that returns an array of Vector3 positions. I then have an array (myArray) that calls this function from time to time. I want to make the array equal to what the function returns. Here is an example.
//This part works fine, like it should.
var myArray : Array = new Array();
myArray = myFunction();
//This returns a Vector3, like it should.
var position : Vector3 = myArray[0];
//The problems come when I try to change myArray later on. myFunction returns different results, so the length and positions returned by myFunction will vary.
myArray = myFunction();
//This causes Unity to crash and an error message saying "Fatal error in Garbage Collector: Too many heap sections". There is nothing wrong with my function. I can call the function as much as I want, and assign it to other variables. The problem comes when I try to reassign it to the same variable.
//I've also tried reassigning myArray to new Array() again before assigning it to myFunction. No luck.
Anyone know what the problem is? I would really appreciate the help. I've been working on this project all night. I've got the whole thing working, but this is the one part that stumped me.
Comment
Your answer
Follow this Question
Related Questions
Huge GC Overhead When Accessing Tris/Verts From Mesh? 2 Answers
Constant crash in Unity - 'too many threads' 2 Answers
GC collects variable that is still in use 1 Answer
Reassigning an Array causing problems 2 Answers
Wrong object always Instantiated 1 Answer