torch/csrc/autograd/function.cpp
/*
 * Note that the custom deleter deletes in BFS style. Without using
 * the custom deleter, the computation graph is deleted in a DFS style.
 * The BFS deletion is valid (and safe) because if a shared_ptr<Function>
 * 's reference count hits 0, nothing else will access it.
 */
Note that the custom deleter deletes in BFS style. Without using
the custom deleter, the computation graph is deleted in a DFS style.
The BFS deletion is valid (and safe) because if a shared_ptr
's reference count hits 0, nothing else will access it.
Note that the custom deleter deletes in BFS style . Without using the custom deleter the computation graph is deleted in a DFS style . The BFS deletion is valid ( and safe ) because if a shared_ptr ' s reference count hits 0 nothing else will access it .
void deleteFunction(Function* function) {
  RecursionDepthCounter recursion_depth;
  if (recursion_depth.value() > kDeleteFunctionMaxRecursionDepth) {
    deleteFunctionQueue.push_back(function);
    return;
  }
  delete function;
  if (deleteFunctionQueue.size() == 0) {
    return;
  }
  if (recursion_depth.value() != kDeleteFunctionMaxRecursionDepth) {
    AT_ERROR("Only one deleter per thread should be able to process "
             "the delete queue. Please open an issue.");
  }
  while (deleteFunctionQueue.size() > 0) {
    auto queued_function = deleteFunctionQueue.front();
    deleteFunctionQueue.pop_front();
    delete queued_function;
  }
}
void deleteFunction ( Function * function ) { RecursionDepthCounter recursion_depth ; if ( recursion_depth . value ( ) > kDeleteFunctionMaxRecursionDepth ) { deleteFunctionQueue . push_back ( function ) ; return ; } delete function ; if ( deleteFunctionQueue . size ( ) == 0 ) { return ; } if ( recursion_depth . value ( ) != kDeleteFunctionMaxRecursionDepth ) { AT_ERROR ( " " " " ) ; } while ( deleteFunctionQueue . size ( ) > 0 ) { auto queued_function = deleteFunctionQueue . front ( ) ; deleteFunctionQueue . pop_front ( ) ; delete queued_function ; } }
Note that the custom deleter deletes in BFS style.
Note that the custom deleter deletes in BFS style .