reference counting for sparse matrix