SwiftData how to release the relationship data after popping the view back

ViewA has ModelA

ViewA loads into the memory. ModelA is queried and shown in the list. ModelA has an array of ModelB which is faulted for the memory.

When you select an item in the list in ViewA ViewB is loaded and ModelB information is displayed.

When you pop back to ViewA, ModelB is still in the memory since it is contained within the array of ModelA.

how could i make this memory efficient by releasing ModelB from the memory. should I refetch everything? or is there another method?

I suppose i am looking something similar to this but for swift data https://developer.apple.com/documentation/coredata/nsmanagedobjectcontext/1506224-refresh

SwiftData how to release the relationship data after popping the view back
 
 
Q