Skip to content

Commit

Permalink
Add a release method to PAGViewController and PAGImageViewController …
Browse files Browse the repository at this point in the history
…to support immediate memory release when called externally. (#2644)
  • Loading branch information
kevingpqi123 authored Dec 30, 2024
1 parent 58711ad commit 6f53f17
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
8 changes: 8 additions & 0 deletions ohos/libpag/src/main/ets/PAGImageView.ets
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,14 @@ export class PAGImageViewController {
this.view = null;
}

/**
* Free up resources used by the PAGImageViewController instance immediately instead of relying on the
* garbage collector to do this for you at some point in the future.
*/
release() {
this.jImageView.release();
}

private composition: PAGComposition | null = null;
private filePath: string | null = null;
private listeners: Array<WeakRef<PAGImageViewListener>> = [];
Expand Down
8 changes: 8 additions & 0 deletions ohos/libpag/src/main/ets/PAGView.ets
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,14 @@ export class PAGViewController {
this.view = null;
}

/**
* Free up resources used by the PAGViewController instance immediately instead of relying on the
* garbage collector to do this for you at some point in the future.
*/
release() {
this.jView.release();
}

uniqueID() {
return this.jView.uniqueID();
}
Expand Down
3 changes: 2 additions & 1 deletion src/platform/ohos/OHOSVideoDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ OHOSVideoDecoder::~OHOSVideoDecoder() {
videoCodec = nullptr;
}
if (codecUserData) {
codecUserData->clearQueue();
delete codecUserData;
}
}
Expand Down Expand Up @@ -271,6 +272,7 @@ std::shared_ptr<tgfx::ImageBuffer> OHOSVideoDecoder::onRenderFrame() {
if (format) {
OH_AVFormat_GetIntValue(format, OH_MD_KEY_VIDEO_STRIDE, &videoStride);
OH_AVFormat_GetIntValue(format, OH_MD_KEY_VIDEO_SLICE_HEIGHT, &videoSliceHeight);
OH_AVFormat_Destroy(format);
}
if (videoStride == 0 || videoSliceHeight == 0) {
return nullptr;
Expand All @@ -291,7 +293,6 @@ std::shared_ptr<tgfx::ImageBuffer> OHOSVideoDecoder::onRenderFrame() {
}
yuvBuffer->lineSize[0] = videoStride;
yuvBuffer->lineSize[1] = videoStride;
OH_AVFormat_Destroy(format);
}
auto capacity = OH_AVBuffer_GetCapacity(codecBufferInfo.buffer);
if (capacity <= 0) {
Expand Down

0 comments on commit 6f53f17

Please sign in to comment.