tailieunhanh - Programming in Objective-C 2.0 edition phần 8

Chúng tôi có focusedbyonnow khi các đối tượng bộ nhớ managementreleasing và khi bạn chủ đề xuyên suốt này nên hiểu bạn có trách nhiệm Mặc dù các ví dụ trong cuốn sách này có tất cả được nhỏ, chúng tôi đã nhấn mạnh tầm quan trọng của việc chú ý đến quản lý bộ nhớ | 17 Memory Management e have focused on the topic of memory management throughout this should understand by now when you are responsible for releasing objects and when you are not. Even though the examples in this book have all been small we have emphasized the importance of paying attention to memory management to teach good programming practice and to develop leak-free programs. Depending on the type of application you re writing judicious use of memory can be critical. For example if you re writing an interactive drawing application that creates many objects during the execution of the program you must take care that your program doesn t continue to consume more memory resources as it runs. In such cases it becomes your responsibility to intelligently manage those resources and free them when they re no longer means freeing resources during the program s execution instead of just waiting until the end. In this chapter you will learn about Foundation s memory-allocation strategy in more detail. This involves a more thorough discussion of the autorelease pool and the idea of retaining will also learn about an object s reference count. Finally we talk about a mechanism known as garbage collection that alleviates the burden of having to retain and subsequently release your objects when you re done using them. However as you ll see garbage collection cannot be used for iPhone applications so you still must understand the techniques for memory management described throughout this book and in more detail in this chapter . The Autorelease Pool You are familiar with the autorelease pool from previous program examples in this second part of the dealing with Foundation programs you must set up this pool to use the Foundation pool is where the system keeps track of your objects for later you ve seen your application can set up the pool with a call like so NSAutoreleasePool pool NSAutoreleasePool alloc init .

TỪ KHÓA LIÊN QUAN