Listing 49-1you have coded two classes, Project and Task, each of whic การแปล - Listing 49-1you have coded two classes, Project and Task, each of whic อังกฤษ วิธีการพูด

Listing 49-1you have coded two clas

Listing 49-1you have coded two classes, Project and Task, each of which have deinit methods that will execute right before these instances are disposed of.
Note Instead of a delegate property in Task, you have a property named parent, which is an optional Project type that a Task instance may use to get information about the project that the Task instance belongs to. Finally, when you instantiate your Project and Task instances, you declare the Project instance as optional. You declare Project as optional because you need to set this instance to nil at the end to dispose of the instance.
When you build and run the application in Listing 49-1, it seems to run fine. But, if you look at the console log, you will notice that no messages were written out even though you expected some. This means the code in deinit was never reached and these five Task instances were never disposed of. This is a memory leak.
You could solve this problem by removing the line of code that assigns the Project instance to the parent property for each Task instance (Listing 49-2).
Listing 49-2. Removing strong Reference
var p:Project? = Project0 pi.name = "Cook Dinner"
let taskNames = ["Choose Menu", "Buy Groceries", "Prepare Ingredients", "Cook Food"]
for name in taskNames{ var t = Task() t.name = name //t.parent = p p!.listOfTasks.append(t)
}
p = nil
When you comment out the line from Listing 49-2, you will get the following output in the console log:
Cook Dinner project is being deinitialized Choose Menu task is being deinitialized Buy Groceries task is being deinitialized Prepare Ingredients task is being deinitialized Cook Food task is being deinitialized
0/5000
จาก: -
เป็น: -
ผลลัพธ์ (อังกฤษ) 1: [สำเนา]
คัดลอก!
Listing 49-1you have coded two classes, Project and Task, each of which have deinit methods that will execute right before these instances are disposed of.Note Instead of a delegate property in Task, you have a property named parent, which is an optional Project type that a Task instance may use to get information about the project that the Task instance belongs to. Finally, when you instantiate your Project and Task instances, you declare the Project instance as optional. You declare Project as optional because you need to set this instance to nil at the end to dispose of the instance.When you build and run the application in Listing 49-1, it seems to run fine. But, if you look at the console log, you will notice that no messages were written out even though you expected some. This means the code in deinit was never reached and these five Task instances were never disposed of. This is a memory leak.You could solve this problem by removing the line of code that assigns the Project instance to the parent property for each Task instance (Listing 49-2).Listing 49-2. Removing strong Referencevar p:Project? = Project0 pi.name = "Cook Dinner"let taskNames = ["Choose Menu", "Buy Groceries", "Prepare Ingredients", "Cook Food"]for name in taskNames{ var t = Task() t.name = name //t.parent = p p!.listOfTasks.append(t)}p = nilWhen you comment out the line from Listing 49-2, you will get the following output in the console log:Cook Dinner project is being deinitialized Choose Menu task is being deinitialized Buy Groceries task is being deinitialized Prepare Ingredients task is being deinitialized Cook Food task is being deinitialized
การแปล กรุณารอสักครู่..
ผลลัพธ์ (อังกฤษ) 2:[สำเนา]
คัดลอก!
Two classes have coded listing 49-1you, Project and Task, each of which have Deinit Will Execute methods that right before these instances are disposed of.
Note Instead of a delegate in Task Property, Property Named You have a parent, which is an optional. Project type that a Task instance may use to get information about the project that the Task instance belongs to. Finally, when you instantiate your Project and Task instances, you declare the Project instance as optional. You Declare Project As You Need to SET optional because this instance to Nil at the End to dispose of the instance.
When You Build and Run the Application in Listing 49 to 1, seems to Run fine. But, if you look at the console log, you will notice that no messages were written out even though you expected some. This means the code in deinit was never reached and these five Task instances were never disposed of. This is a memory leak.
You could Problem Solve this by removing the line of code that assigns the instance to the parent Project Property Task for each instance (Listing 49 to 2).
Listing 49 to 2. Reference removing strong
var P: Project? = Project0 Pi.name = "Cook Dinner"
let TaskNames = ["Choose Menu", "Buy Groceries", "Prepare Ingredients", "Cook Food"]
{var TaskNames for name in T = Task () = T.name name. //t.parent = PP! .listOfTasks.append (T)
}
P = Nil
Comment out the line from Listing When You forty-nine to two, You Will Get the following output in the Console log:
Cook Dinner Project is being Deinitialized Choose Menu. task is being deinitialized Buy Groceries task is being deinitialized Prepare Ingredients task is being deinitialized Cook Food task is being deinitialized.
การแปล กรุณารอสักครู่..
ผลลัพธ์ (อังกฤษ) 3:[สำเนา]
คัดลอก!
Listing 49-1you have coded two classes Project Task, and, of each which have deinit methods that will execute right before. These instances are disposed of.
Note Instead of a delegate property in Task you have, a property named parent which is,, An optional Project type that a Task instance may use to get information about the project that the Task instance belongs. Finally to,.When you instantiate your Project and Task instances you declare, the Project instance as optional. You declare Project. As optional because you need to set this instance to nil at the end to dispose of the instance.
When you build and run the. Application in, Listing 49-1 it seems to run fine. But if you, look at the, console logYou will notice that no messages were written out even though you expected some. This means the code in deinit was never. Reached and these five Task instances were never disposed of. This is a memory leak.
You could solve this problem by removing. The line of code that assigns the Project instance to the parent property for each Task instance (Listing 49-2).
Listing 49-2.Removing strong Reference
var P: Project? = Project0 pi.name = "Cook Dinner"
let taskNames = ["Choose Menu", "Buy Groceries",. "Prepare Ingredients", "Cook Food"]
for name in taskNames {var t = Task () T.Name = name / / t.parent = P P!. listOfTasks.append (T)
}
P. = nil
When you comment out the line from, Listing 49-2 you will get the following output in the console log:
.Cook Dinner project is being deinitialized Choose Menu task is being deinitialized Buy Groceries task is being deinitialized. Prepare Ingredients task is being deinitialized Cook Food task is being deinitialized
.
การแปล กรุณารอสักครู่..
 
ภาษาอื่น ๆ
การสนับสนุนเครื่องมือแปลภาษา: กรีก, กันนาดา, กาลิเชียน, คลิงออน, คอร์สิกา, คาซัค, คาตาลัน, คินยารวันดา, คีร์กิซ, คุชราต, จอร์เจีย, จีน, จีนดั้งเดิม, ชวา, ชิเชวา, ซามัว, ซีบัวโน, ซุนดา, ซูลู, ญี่ปุ่น, ดัตช์, ตรวจหาภาษา, ตุรกี, ทมิฬ, ทาจิก, ทาทาร์, นอร์เวย์, บอสเนีย, บัลแกเรีย, บาสก์, ปัญจาป, ฝรั่งเศส, พาชตู, ฟริเชียน, ฟินแลนด์, ฟิลิปปินส์, ภาษาอินโดนีเซี, มองโกเลีย, มัลทีส, มาซีโดเนีย, มาราฐี, มาลากาซี, มาลายาลัม, มาเลย์, ม้ง, ยิดดิช, ยูเครน, รัสเซีย, ละติน, ลักเซมเบิร์ก, ลัตเวีย, ลาว, ลิทัวเนีย, สวาฮิลี, สวีเดน, สิงหล, สินธี, สเปน, สโลวัก, สโลวีเนีย, อังกฤษ, อัมฮาริก, อาร์เซอร์ไบจัน, อาร์เมเนีย, อาหรับ, อิกโบ, อิตาลี, อุยกูร์, อุสเบกิสถาน, อูรดู, ฮังการี, ฮัวซา, ฮาวาย, ฮินดี, ฮีบรู, เกลิกสกอต, เกาหลี, เขมร, เคิร์ด, เช็ก, เซอร์เบียน, เซโซโท, เดนมาร์ก, เตลูกู, เติร์กเมน, เนปาล, เบงกอล, เบลารุส, เปอร์เซีย, เมารี, เมียนมา (พม่า), เยอรมัน, เวลส์, เวียดนาม, เอสเปอแรนโต, เอสโทเนีย, เฮติครีโอล, แอฟริกา, แอลเบเนีย, โคซา, โครเอเชีย, โชนา, โซมาลี, โปรตุเกส, โปแลนด์, โยรูบา, โรมาเนีย, โอเดีย (โอริยา), ไทย, ไอซ์แลนด์, ไอร์แลนด์, การแปลภาษา.

Copyright ©2024 I Love Translation. All reserved.

E-mail: