Question

Is it wise to create views in Cocoa that have dimensions around 15000 pixels? (of course only small part of this view will be visible at a time in a NSScrollView)

Interface Builder has limit of 10000 pixels in size. Is this an artificial limitation or is there a good reason behind it?

Should I just create huge view and let NSScrollView/Quartz worry about rendering it efficiently (my view is drawn programmatically within area requested in drawRect) or do I risk excessive memory usage and other problems? (e.g. could OS X try to cache whole view's bitmap in video memory at any time?)

Was it helpful?

Solution

Views don't have backing stores, unless they are layer-backed. The window is what has the backing store, so the amount of memory used to display the view is limited to the size of the window.

So, the answer is yes. Go ahead and make your views as big as you want.

(Of course, you'll want to limit the drawing you do in the view to the rect passed in drawRect: or you'll be wasting a lot of time doing invisible drawing.)

OTHER TIPS

Well, if Cocoa does try to cache the entire view in memory, that would be a problem:

10000 * 10000 = 100,000,000
* 4 = 400,000,000

That's 400 MB in raw RGBA pixels for one view. If we want to be really pessimistic, assume that NSView is double-buffering that for you, in which case your memory usage doubles to 800 MB.

In the worst case, your user is running your app on an old Mac mini with 1 GB of RAM—of which you have just used 80%. The system will certainly start paging way before this point, making their system unbearably slow.

On the other hand, it is the easiest way to implement it that I can think of, so I say try it and see what Activity Monitor says about your memory usage. If it's too high, try changing various options of the scroll view and clip view; if that doesn't work, I can think of nothing else but to make your own scrollers and fake it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top