Telling IKImageBrowserView not to schedule preloading

懵懂的女人 提交于 2020-01-01 06:51:26

问题


For our rewrite of the open-source iMedia framework project (in use currently by dozens of developers), we are switching to IKImageBrowserView, and having a troubling time with caching.

It appears that IKImageBrowserView likes to preload/prefetch a cache of images, as a low-priority background task, as many not-yet-visible items that it can. This might be useful, except that we don't want to load the CPU (and network for remotely-retrieved images) if we can help it.

Especially since we have our own FIFO caching mechanism (so we can share our thumbnail data with other views into the same data), all this is doing is filling up the cache up to capacity and then causing the older items to be dumped.

Is there some way to disable the scheduling of this preloader? (Even if there is an undocumented API that we can gingerly use for now, I'll be sure to open up a request to make it into a public API, since it is really critical to be able to turn this dangerous capability off.)

This will really affect a lot of applications. Any work-arounds you can suggest would be very much appreciated.

BTW Some related discussion: http://lists.apple.com/archives/cocoa-dev/2007/Nov/msg02011.html


回答1:


I've been starting to use IKImageBrowserView myself, and I hadn't noticed this before, but indeed I tried it out and am seeing the same behavior with my own app.

It looks like there's a private method on IKImageBrowserView called _shouldProcessLongTasks. I tried overriding it to just return NO, and that appears to prevent the preloading behavior for images that aren't yet visible in the view (at least under Snow Leopard, would have to test under Leopard to see if the behavior is the same). Seems like a fairly low-risk private API usage, since if the method changes, it simply won't be called anymore. When you file a bug with Apple on this, do post the radar number so others affected can file a dupe on it and try to get a public API and/or behavior change for this.

For the record, it looks like the current behavior is that it will prefetch stuff in the background as long as the application is in the foreground and the window containing the view is key. If you switch to another app or window, then it stops preloading.



来源:https://stackoverflow.com/questions/1540426/telling-ikimagebrowserview-not-to-schedule-preloading

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!