nus-cs2103-AY2324S2 / forum

16 stars 0 forks source link

When do you need to use the delete symbol #1044

Closed justincred closed 6 months ago

justincred commented 6 months ago

As shown below, the lifeline is deleted, however when do u have to do that as this would mean that every time u would need to delete the class after finish using them no? image

aureliony commented 6 months ago

every time u would need to delete the class after finish using them no

Only if the object has no more references (i.e., ready for garbage collection). In this case, when cook() method returns, the d object is no longer referenced at that exact point in time, so the X is required (note that the return arrow coincides horizontally with the X to indicate that they occur at the same time).

In other cases, the object may continue being referenced and we may not know when it is ready for garbage collection.

damithc commented 6 months ago

note that the return arrow coincides horizontally with the X to indicate that they occur at the same time

@aureliony This is more of a happy coincidence. We are not so particular about the horizontal alignment of the X, provided it appears after (and not before) it is no longer referenced.

Li-Zizhen commented 6 months ago

@damithc Sorry, is the deletion X compulsory?

justincred commented 6 months ago

hi @damithc ,so this is for like temporary variables?

damithc commented 6 months ago

@damithc Sorry, is the deletion X compulsory?

In general, show only if it adds value to the purpose of the diagram. In the exam, consider it as compulsory (i.e., if you forgot or put it in the wrong location, it can affect your ability to pick the expected answer in related MCQs as well).

justincred commented 6 months ago

hi @damithc then may i ask do i put the object deletion symbol at the end for unit since it was a temporary variable created during the function? here image

damithc commented 6 months ago

hi @damithc then may i ask do i put the object deletion symbol at the end for unit since it was a temporary variable created during the function? here

@justincred yes, you can.

justincred commented 6 months ago

thanks prof