Note that there are some explanatory texts on larger screens.

plurals
  1. POUIView assigned with objectAtIndex allocates too much memory
    text
    copied!<p>After hours of sitting on this problem (I really feel like a chicken on a dragon egg) I come here to ask.</p> <p>The problem is: I have an async queue with my timer (created with mach_absolute_time()) which after some time interval gives NSNotification to defaultCenter, which then runs my method. In the run method, there is a method call for finding out intersections of views. I recently switched to ARC as it seemed to be a really good idea. Now I regret it a bit, since pre-ARC, this code did allocate and deallocate correctly, but now it only allocates itself. Maybe I'm missing some code to deallocate it manually, however, when I tried to set the view to nil, it did not help at all. Also, in Allocations, the malloc 4.00 KB keeps raising because of that intersect method, which is really the reason why I ask, since after some time, it reaches a limit, I receive a memory warning and my app crashes.</p> <p>The reason I need this method is that I iterate through subviews of view with obstacles. And when distance of another view from some of the subviews reaches limit, I run some code.</p> <p>So now for some code: This is the method that allocates so much memory, precisely the first line of it (pre-ARC, it was way longer, but I reduced it to get the thing which creates allocations). When I remove it, the infinite allocations stop. Just a note again: This method gets called a really really lot of times a second, and on a different queue from main queue.</p> <pre><code>- (BOOL)obstacleIntersect { UIView *view = [[self subviews] objectAtIndex:0]; return NO; } </code></pre> <p>And this is how it looks in Allocations: <a href="http://img36.imageshack.us/img36/7216/mallocations.png" rel="nofollow">Mallocations</a></p> <p>Thanks for any help and for reading, since you've just reached an end of this long question.</p> <p>EDIT: This is how the code should look with all the functionality etc. The reason I posted the code above with only one line is because now I don't care if it works like it should or not, I just want to solve the allocation problem. Sorry for misleading. As for the uiview particle, it is the view which intersects with already mentioned subviews. This code also produces same infinite allocations.</p> <pre><code>- (BOOL)obstacleIntersect { for(UIView *view in [[[self subviews] objectAtIndex:0] subviews]) { if (sqrt(pow(abs(particle.center.x - view.center.x), 2) + pow(abs(particle.center.y - view.center.y), 2)) &lt; particle.frame.size.width / 2 - 1) { return YES; } } return NO; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload