Skip to content

Commit

Permalink
Merge pull request #663 from karlnapf/master
Browse files Browse the repository at this point in the history
SG_REF based memory leak fixes
  • Loading branch information
karlnapf committed Jul 20, 2012
2 parents d80d9d3 + fab1560 commit 8484f8f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/shogun/features/CombinedFeatures.cpp
Expand Up @@ -355,11 +355,19 @@ CFeatures* CCombinedFeatures::copy_subset(SGVector<index_t> indices)
processed->add(current, new_element);
}
else
{
new_element=processed->get_element(current);

/* has to be SG_REF'ed since it will be unrefed afterwards */
SG_REF(new_element);
}

/* add to result */
result->append_feature_obj(new_element);

/* clean up: copy_subset of SG_REF has to be undone */
SG_UNREF(new_element);

SG_UNREF(current);
current=get_next_feature_obj();
}
Expand Down
11 changes: 8 additions & 3 deletions src/shogun/machine/KernelMachine.cpp
Expand Up @@ -462,13 +462,18 @@ void CKernelMachine::store_model_features()
CFeatures* sv_features=lhs->copy_subset(m_svs);
SG_UNREF(lhs);

/* now sv indices are just the identity */
m_svs.range_fill();

/* set new lhs to kernel */
kernel->init(sv_features, rhs);

/* unref rhs */
SG_UNREF(rhs);

/* was SG_REF'ed by copy_subset */
SG_UNREF(sv_features);

/* now sv indices are just the identity */
m_svs.range_fill();

}

bool CKernelMachine::train_locked(SGVector<index_t> indices)
Expand Down
3 changes: 3 additions & 0 deletions src/shogun/machine/KernelMulticlassMachine.cpp
Expand Up @@ -50,6 +50,9 @@ void CKernelMulticlassMachine::store_model_features()
/* now, features are replaced by concatenated SV features */
kernel->init(sv_features, rhs);

/* was SG_REF'ed by copy_subset */
SG_UNREF(sv_features);

/* now the old SV indices have to be mapped to the new features */

/* update SV of all machines */
Expand Down

0 comments on commit 8484f8f

Please sign in to comment.