jni memory leak fix
This commit is contained in:
@@ -80,13 +80,6 @@ namespace repository {
|
||||
|
||||
std::stringstream buff(data);
|
||||
std::vector<char> vals(data.begin(), data.end());
|
||||
//vals.reserve(data.size());
|
||||
//vals.assign(data.begin(), data.end());
|
||||
/**
|
||||
vals.assign(std::istream_iterator<unsigned char>(buff),
|
||||
std::istream_iterator<unsigned char>());
|
||||
*/
|
||||
//std::copy(data.begin(), data.end(), &vals);
|
||||
|
||||
return vals;
|
||||
}
|
||||
|
||||
@@ -79,6 +79,12 @@ jobject songToObj(JNIEnv *env, const model::Song& song)
|
||||
env->CallVoidMethod(songObj, songYear, year);
|
||||
env->CallVoidMethod(songObj, songCoverArtId, coverArtId);
|
||||
|
||||
env->DeleteLocalRef(title);
|
||||
env->DeleteLocalRef(album);
|
||||
env->DeleteLocalRef(albumArtist);
|
||||
env->DeleteLocalRef(artist);
|
||||
env->DeleteLocalRef(genre);
|
||||
|
||||
return songObj;
|
||||
}
|
||||
|
||||
@@ -290,8 +296,12 @@ Java_com_example_mear_repositories_TrackRepository_retrieveSongs(
|
||||
auto allSongs = retrieveSongs(tk, uri);
|
||||
jobjectArray songs = env->NewObjectArray(allSongs.size(), songClass, nullptr);
|
||||
for (auto i = 0; i != allSongs.size(); ++i) {
|
||||
auto song = songToObj(env, allSongs[i]);
|
||||
env->SetObjectArrayElement(songs, i, song);
|
||||
try {
|
||||
auto song = songToObj(env, allSongs[i]);
|
||||
env->SetObjectArrayElement(songs, i, song);
|
||||
} catch (std::exception& ex) {
|
||||
auto msg = ex.what();
|
||||
}
|
||||
}
|
||||
|
||||
return songs;
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace repository {
|
||||
if (fullUri.at(fullUri.size()-1) != '/') {
|
||||
fullUri.append("/");
|
||||
}
|
||||
//fullUri.append("api/v1/song");
|
||||
|
||||
fullUri.append(songRecordEndpoint());
|
||||
std::vector<model::Song> songs;
|
||||
|
||||
@@ -120,11 +120,4 @@ namespace repository {
|
||||
((std::string*)e)->append((char*)ptr, size * nmemb);
|
||||
return size * nmemb;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
constexpr auto SongRepository::songRecordEndpoint() noexcept {
|
||||
return "api/v1/song";
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user