views:

53

answers:

2

I have created a UIScrollView (canvas.scrollview) and have a custom UIView (canvas) inside it.

A normal configuration for starting up is something like this:

CGRect cs2 = CGRectMake(0, 0, 4000, 4000); CGPoint screen = {[UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height};

self.canvas.frame = cs2; //canvas_size;

self.canvas.scrollView.contentSize = canvas_size.size; self.canvas.scrollView.contentOffset = CGPointMake(canvas_size.size.width/2-screen.x/2, canvas_size.size.height/2-screen.y/2);

But I have noticed that when I set the scrollview content size to a larger value such as 4000,4000; it will use a lot more memory. For example:

scrollview   view  real virtual
1000,1000 1000,1000 6  88
4000,4000 1000,1000 62  145
1000,1000 4000,4000 6  88

I would like to have a fairly large working area if possible, but 8000x8000 completely foobars the memory. Any idea why the scrollview would use up so much memory, and is there a way to fix this?

A: 

I don't think it's the scroll view that is using up so much memory, but the canvas custom UIView subclass. If canvas is really 4000 x 4000, the system has to allocate enough memory to hold a 32-bit deep bitmap of that size, or about 64 MB. For such large views, you should use CATiledLayer for static content, or some kind of tiled view system.

lucius
A: 

I use huge scroll views in my current project (thousands by thousands of pixels) and this is definitely not occuring for me. I think your UIView being enormous might be the problem, not your scroll view. Try setting the UIView's size to 768x1024 and then up the scroll view to 4k x 4k and see if the problem goes away.

If the UIView happens to be an image (I doubt it, or you'd probably mention it), you should be aware that iOS only supports images up to 1024x1024 in size, after which there is a bit of "undefined behavior" in terms of memory usage. You probably need to look into CATiledLayer, though a plain UIView without content shouldn't take up that much memory no matter how big it is, so there might be an issue elsewhere in your project as well.

Kalle