Skip to content

Releasing memory for TF_STRING (TF_TString) #200

Answered by serizba
ns-wxin asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @ns-wxin @ljn917

I checked the problem with the TF_STRING. The solution in #128 does not work, as it deallocates before using the tensor.

It seems that when resizing the string, then the extra buffer is not cared by TF_DeleteTensor. I think that a simple workaround would be to change the deallocator to also take into account the TF_STRING, like this:

inline tensor::tensor(const std::string& value) {
    auto deallocator = [](TF_Tensor* tft) {
        TF_TString* tstr = static_cast<TF_TString*>(TF_TensorData(tft));
        TF_DeleteTensor(tft);
        TF_TString_Dealloc(&tstr[0]);
    };
    
    this->tf_tensor = {TF_AllocateTensor(static_cast<enum TF_DataType>(TF_STRING), nullptr, 0, s…

Replies: 7 comments 7 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@ns-wxin
Comment options

Comment options

You must be logged in to vote
1 reply
@ns-wxin
Comment options

Comment options

You must be logged in to vote
3 replies
@ljn917
Comment options

@serizba
Comment options

@serizba
Comment options

Answer selected by serizba
Comment options

You must be logged in to vote
2 replies
@serizba
Comment options

@ns-wxin
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants